s2sh框架搭建mysql_S2SH项目框架搭建(完全注解)
1.引入相关jar包
2.配置Spring配置文件,命名为applicationContext.xml(配置好后放到src目录下)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
value="com.mysql.jdbc.Driver">
value="jdbc:mysql://localhost:3306/db_studentInfo">
true
true
org.hibernate.dialect.MySQLDialect
com.java1234.model.User
com.java1234.model.Grade
com.java1234.model.Student
3.配置web.xml文件
S2SHStudentInfoManage
index.jsp
StrutsPrepareAndExecuteFilter
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
StrutsPrepareAndExecuteFilter
/*
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
4.示例daoImpl
package com.java1234.dao.impl;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.java1234.dao.UserDao;
import com.java1234.model.User;
@Repository
public class UserDaoImpl implements UserDao{
private SessionFactory sessionFactory;
@Override
public User login(User user) throws Exception {
User resultUser=null;
Session session=this.getSession();
Query query=session.createQuery("from User u where u.userName=? and u.password=?");
query.setString(0, user.getUserName());
query.setString(1, user.getPassword());
@SuppressWarnings("unchecked")
List userList=(List)query.list();
if(userList.size()>0){
resultUser=userList.get(0);
}
return resultUser;
}
@Resource
@Autowired
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getSession(){
return sessionFactory.getCurrentSession();
}
}
5.示例serviceImpl
package com.java1234.service.impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.java1234.dao.UserDao;
import com.java1234.model.User;
import com.java1234.service.UserService;
@Service
public class UserServiceImpl implements UserService{
@Resource
private UserDao userDao;
@Override
public User login(User user) throws Exception {
return userDao.login(user);
}
}
6.示例Action
package com.java1234.action;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import com.java1234.model.User;
import com.java1234.service.UserService;
import com.java1234.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;
@Scope("prototype")
@Namespace("/")
@Action(value="login",results={@Result(name="success",type="redirect",location="/main.jsp"),@Result(name="error",location="/index.jsp")})
public class LoginAction extends ActionSupport implements ServletRequestAware{
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource
private UserService userService;
private User user;
private String error;
private String imageCode;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public String getImageCode() {
return imageCode;
}
public void setImageCode(String imageCode) {
this.imageCode = imageCode;
}
HttpServletRequest request;
@Override
public String execute() throws Exception {
// 获取Session
HttpSession session=request.getSession();
if(StringUtil.isEmpty(user.getUserName())||StringUtil.isEmpty(user.getPassword())){
error="用户名或密码为空!";
return ERROR;
}
if(StringUtil.isEmpty(imageCode)){
error="验证码为空!";
return ERROR;
}
if(!imageCode.equals(session.getAttribute("sRand"))){
error="验证码错误!";
return ERROR;
}
try {
User currentUser=userService.login(user);
if(currentUser==null){
error="用户名或密码错误!";
return ERROR;
}else{
session.setAttribute("currentUser", currentUser);
return SUCCESS;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
@Override
public void setServletRequest(HttpServletRequest request) {
// TODO Auto-generated method stub
this.request=request;
}
}
s2sh框架搭建mysql_S2SH项目框架搭建(完全注解)相关推荐
- 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之八 || API项目整体搭建 6.3 异步泛型仓储+依赖注入初探...
代码已上传Github+Gitee,文末有地址 番外:在上文中,也是遇到了大家见仁见智的评论和反对,嗯~说实话,积极性稍微受到了一丢丢的打击,不过还好,还是有很多很多很多人的赞同的,所以会一直坚持下去 ...
- 15分钟用Java平台实现Springboot框架构建后端项目框架
15分钟用Java平台实现Springboot框架构建后端项目框架 文章目录 15分钟用Java平台实现Springboot框架构建后端项目框架 前言 准备工具 1. 新建项目 2.搭建项目框架 3. ...
- 从壹开始前后端分离【 .NET Core2.2 +Vue2.0 】框架之六 || API项目整体搭建 6.1 仓储+服务+抽象接口模式...
前言 1.@LearningCoding 小伙伴关于用Sqlsugar在mysql数据库上的研究成果: sqlsugarcore支持mysql等数据库,在DbContext里面只需要设置dbtype为 ...
- Vue项目实战之人力资源平台系统(一)框架介绍及项目环境搭建
前言 目录 前言 一.vue-element-admin简介 二.项目环境搭建 2.1 nodejs环境 2.2 git版本控制 2.3 vscode编辑器 三.拉取vue-element-admin ...
- 使用vue-cli脚手架搭建简单项目框架
1.首先已经安装了node,最好版本6以上. 2.安装淘宝镜像 大家都知道国内直接使用 npm 的官方镜像是非常慢的,这里推荐使用淘宝 NPM 镜像.这样就可以直接使用cnpm了. npm insta ...
- idea搭建springcloud项目_Eureka搭建分布式SpringCloud项目
@Author:By Runsen SpringCloud Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册 ...
- 【5分钟系列】搭建基于docker环境搭建下springboot-mysql项目框架
在云时代,开发者创建的应用必须要能很方便地在网络上传播,也就是说应用必须脱离底层物理硬件的显示:同时必须是"任何时间任何地点"可获取的.我们通常想要快速搭建一个项目框架,数据库的环 ...
- Vue项目脚手架搭建
Vue项目脚手架搭建 Vue 项目脚手架搭建需要的工具 安装NodeJs 安装vue-cli 安装webpack 初始化项目 启动项目 Vue 项目脚手架搭建需要的工具 NodeJs vue-cli ...
- 使用maven搭建ssm框架的javaweb项目
目前主流的javaweb项目,常会用到ssm(Spring+Spring MVC+Mybatis)框架来搭建项目的主体框架,本篇介绍搭建SSM框架的maven项目的实施流程.记之共享! 一.SSM框架 ...
最新文章
- Android 获取App的版本号与版本名称的2中方法
- 微信小程序之可滚动视图容器组件 scroll-view
- Thinkphp5中异常处理不返回页面返回Json格式的字符串
- SAP CRM One Order object type in line item - when it is filled
- c++ socket学习(1.3)
- 前端学习(2702):重读vue电商网站23之element-ui 如何按需导入
- 给Windows 服务添加命令行参数
- Git 修改已提交 commit 的信息
- [转]GO err is shadowed during return
- php代码高亮正则,php通过正则表达式实现语法高亮
- 恢复Visual SourceSafe已删除的文件
- win10远程计算机证书错误,设置win10系统ie证书错误的详细办法
- Bazel5.0.0源码安装报错:no matching function for call to ‘StrFormat(const char [28], const char*)’
- ICCV 2021 Oral | Paint Transformer - 基于笔触预测的快速油画渲染算法
- vbox的虚拟机Ubuntu的共享文件夹无法创建软链的问题解决
- 自制瘦腰减肥茶 一月减掉小肚子
- Cordys BOP 4平台开发入门实战演练——会签流程建模开发
- 女性向游戏难复制下一个“恋与”,从日本游戏能取到什么经?
- 什么是“软件定义汽车”
- cad 二次开发 插入图片_CAD 二次开发 引用外部DWG并放到对应图层上
热门文章
- nginx负载均衡器处理session共享的几种方法(转)
- openstack【Kilo】汇总:包括20英文文档、各个组件新增功能及Kilo版部署
- VC++中对话框数据交换【十全十美】
- code vs 集成tfs_10大Python集成开发环境和代码编辑器
- lol游戏挂机软件_直男玩家吐槽LOL手游:挂机,送头,队友菜
- 计算机毕业设计中用Java编写泛型与集合框架
- oracle 客户端连接数_查看oracle数据库允许的最大连接数和当前连接数
- python如何爬取图片到指定文件夹论文_基于Python的图片爬虫程序设计
- 右键菜单_右键菜单太长会导致电脑卡顿?轻松删除右键菜单无用项
- 转hdmi_LT8619CHDMI转LVDS-HDMI支持高达4Kx2K_30Hz的分辨率