SSM整合
Spring–SpringMVC–MyBatis
第1步. Spring – MyBatis
真正需要整合:将MyBatis的 SqlSessionFactory 交给Spring管理
第2步. Spring – SpringMVC
就是将Spring – SpringMVC各自配置一遍
SM整合步骤
1.jar包
2.类-----表
Student类—student表
3.MyBatis的配置文件conf.xml(数据源、Mapper.xml映射文件路径)----可省略,将该文件中的配置全部交由Spring管理。
spring配置文件: applicationContext.xml
4.通过Mapper.xml将 类和表 建立映射关系
5.之前使用MyBatis:conf.xml----->SqlSessionFactory
现在整合的时候,需要通过Spring管理SqlSessionFactory
配置spring配置文件(applicationContext.xml) (Web项目):
web.xml:(web中引入Spring)
6.使用Spring整合MyBatis:核心是 将MyBatis的SqlSessionFactory交给Spring管理
上面basePackage所在的property的作用:
将org.lanqiao.mapper包中,所有的接口 产生与之对应的 动态代理对象(对象名就是首字母小写的接口名):studentMapper.queryAllStudent();
SS整合
7.继续整合SpringMVC:将Springmvc加入项目即可
a.加入SpringMVC所需的jar包
spring-webmvc.jar
b.配置SpringMVC(给项目加入SpringMVC支持)
web.xml: dispatcherServlet
c.编写SpringMVC配置文件
applicationContext-controller.xml:视图解析器、基础配置
d.示例