搭建SSH注解开发的环境
创建web项目,引入jar包
- SSH整合的jar包
- Struts2的注解开发包
- struts2-convention-plugin-2.3.24.jar ------Struts2的注解开发包
引入配置文件
- web.xml
Struts2的过滤器
Spring的监听器
- jdbc.properties
- log4j.properties
- applicationContext.xml
创建相关的包和类
引入相关页面
保存客户
1、编写Action的save方法
2、配置Action
在Spring中配置Action,Action交给Spring管理(使用注解方式)
- 开启组件扫描
- 在类上添加注解
在Struts中配置Action,Action负责处理请求和页面跳转
3、Action调用业务层
- Service交给Spring管理
- Action中注入Service
- 在Action的放法中调用业务层
4、在Service中调用DAO
- 将DAO交给Spring管理
- 在Service中注入DAO
5、创建实体和映射(映射使用的是注解)
- 现在映射使用注解实现(将表和类建立关系,将表中的字段和类中的属性建立关系)
6、在Spring中整合Hibernate
7、在DAO中使用模板
不能让DAO继承HibernateDaoSupport,因为属性注入不能使用注解方式。
- 定义Hibernate模板
- 注入模板
- 在DAO中使用模板完成保存
8、配置事务管理器
- 开启注解事务
- 在业务层添加注解