加入Spring
1、导jar包
2、配置web.xml文件、添加启动Spring容器的Listener

3、添加Spring核心配置文件applicationContext.xml
4、注意:在创建applicationContext.xml时、要导入aop、tx、beans三个命名空间、以便在下边整合其他框架、配置时使用。
加入Hibernate
1、导入jar包
2、建立持久化类、和其对应的.hbm.xml映射文件、
3、Spring整合Hibernate
1、配置数据源(数据库连接信息、连接池、数据库方言等一系列信息)

2、构建sessionFactory
- 用到的类 :org.springframework.orm.hibernate5.LocalSessionFactoryBean
-在sessionFactory中指定dataSource(也就是我们上边配置的数据源)
-配置实体类的hbm.xml映射文件、因为实体映射文件一般都为多份、故要用list来放。

3、配置声明式事务
- 1、配置事务管理器、需要用到的类:org.springframework.orm.hibernate5.HibernateTransactionManage、并注入会话工厂

- 2、配置通知、也就是要对哪些方法添加事务

-3、配置切面AspetJ(advice-ref="txAdvice"指向上边配置的通知)

加入Struts2
1、加jar包
2、加入struts.xml
3、整合Spring
编写Dao层和Service层
1、编写 dao层(数据访问层) Dao DaoImpl 注意:DaoImpl继承HibernateDaoSupport类。
2、service层(业务层) ServiceImpl 注入Dao层的实现类
3、在application.xml中配置相应的Dao层、Service层。
编写Action类
1、编写Action 相应的Action类、注入Service层、以及要用到的实例、集合等。
2、编写相应的动作方法、执行相应的业务层、返回相应的视图、在struts.xml中配置。
网友评论