ssh框架整合的步骤

ssh用xml实现的步骤:
1.配置hibernate
a.在pom.xml中加载相关jar包(hibernate-core-5.2.12.Final)
b.配置hibernate.cfg.xml(只负责显示和格式化sql语句,数据库的连接和映射的文件交给了spring去实现)
c.写实体类以及实体类的hibernate文件(Person.hbm.xml,在数据库里建表建列)
d.在hibernate.cfg.xml中引入映射文件Person.hbm.xml(当配置spring时就不需要了)
e.通过junit对hibernate框架进行测试
1).new 一个Configuration读取hibernate配置文件
2).通过configuration获取SessionFactory
3).通过sessionFactory获取session
4) .开启事务
5) .进行操作
6).提交事务
7) .关闭资源
这里写图片描述

注意:在单独使用Hibernate框架时,还是要在hibernate.cfg.xml中连接数据库以及关联映射文件

2.配置Spring
a.在pom.xml中加载 Spring-context-4.3.12.RELEASE和spring对于hibernate的依赖Spring-orm-4.3.12.RELEASE
b.给每一个包建一个xml,最重要的是applicationContext-public.xml
c.在资源文件中写一个连接数据库的db.properties的文件
d.在applicationContext-public.xml中
1).引入数据库的连接db.properties
这里写图片描述
2).配置数据源:配置数据源的连接池c3p0,引入c3p0jar包,将db.properties的值赋值到对应的地方
3).配置Sessionfactory,引入数据源吧,加载hibernate配置文件,加载映射文件( entity下所有实体类对应的映射文件)
4) .建一个事务管理器
5) . 配置事务的属性
6).配置事务的切点 ,对应的包
这里写图片描述
e.写dao,service层代码,实现每个包的配置文件,dao层引用sessionFactory,service层关联dao层
f.测试spring,读取spring的配置文件
ApplicationContext ac=new ClassPathXmlApplicationContext(new String[] {“applicationContext-public.xml”,”applicationContext-service.xml”,”applicationContext-dao.xml”});
得到service层的service
PersonServiceInterface personservice= (PersonServiceInterface) ac.getBean(“PersonserviceImp”);
调用方法

3.配置struts2
a.引入核心包struts2-core-2.5.12,对spring的支持包struts2-convention-plugin-2.5.12
b.配置action的配置文件
c.配置Struts2的配置文件,引入actoin
d.配置web.xml 1.加载Struts2 2.加载spring

注意:通过struts配置调用Actoion,action调service,service调 dao,一层一层关系之间相互依赖

猜你喜欢

转载自blog.csdn.net/qq_40158032/article/details/78829284