Struts2.1、Spring3.0、Hibernate3.3 框架整合-用户登录示例(更新)
Struts2.1、Spring3.0、Hibernate3.3 框架整合-用户登录
示 例(更新)
目录
1 数据库(已有数据库可跳过直接浏览第二节)..........................................................................3
2 创建项目...........................................................................................................................................3
2.1 在 MyEclipse 中创建数据库连接........................................................................................4
2.2 为项目添加 Struts 能力.........................................................................................................8
2.3 为项目添加 Spring 能力.....................................................................................................11
2.4 为项目添加 Hibernate 能力................................................................................................14
2.5 搭建项目结构(分包).....................................................................................................19
3 搭建项目结构(model、dao 生成)............................................................................................21
4 搭建项目结构(service、web 编写)..........................................................................................28
4.1 编写 service 层代码,创建 IUsersService 接口和 UsersService 实现类,编写 CRUD 的
方法。.........................................................................................................................................28
4.1.1 创建 IUsersService 接口..........................................................................................28
4.1.2 创建 UsersService 实现类........................................................................................30
4.2 编写 web 层 UsersAction 代码,用于对用户增删改查进行处理...................................33
5 搭建项目结构(配置文件编写)................................................................................................38
5.1 补充 applicationContext.xml 配置文件,装配注入关系和事务处理..............................38
5.1.1 增加 spring 配置文件节点的命名空间,否则事务处理节点不识别:..............38
5.1.2 增加事务处理机制..................................................................................................38
5.1.3 增加装配关系...........................................................................................................39
5.2 配置 Struts.xml....................................................................................................................40
5.3 配置 web.xml.......................................................................................................................41
6 搭建项目结构(页面代码).........................................................................................................42
6.1 user_add.jsp..........................................................................................................................42
6.2 user_edit.jsp.........................................................................................................................42
6.3 user_list.jsp..........................................................................................................................43
6.4 login.jsp................................................................................................................................43
6.5 welcome.jsp..........................................................................................................................44
6.6 error.jsp.................................................................................................................................44
6.7 部署......................................................................................................................................45
6.7.1 打开服务器视图......................................................................................................45
6.7.2 在 tomcat 服务器上添加项目的部署......................................................................45
6.8 测试运行..............................................................................................................................46
6.8.1 启动服务器...............................................................................................................46
6.8.2 登录...........................................................................................................................47
6.8.3 添加用户...................................................................................................................49
第 1 页 共 52 页