1. 整合思路
在mybatis和spring整合的基础上,添加springMVC进行整合。
spring要管理springMVC编写的Handle(Controller)、mybatis的sqlSessionFactory、mapper。
第一步:整合dao,spring和mybatis整合。
第二步:整合service,spring管理service接口,service中可以调用spring容器中的dao(mapper)。
第三步:整合contrioller,spring管理controller接口,在controller调用service。
2. 应该导入的jar包
mybatis:3.2.7
spring:3.2.0
mybatis的jar
mybatis和spring整合包
spring的所有jar包(包括 springmvc的包)
数据库驱动包
log4j日志
3. 配置文件
applicationContext-dao.xml---配置mybatis的数据源、SqlSessionFactory、mapper扫描器
applicationContext-service.xml---配置service接口
applicationContext-transaction.xml--使用声明式事务管理,配置文件配置事务
sprintmvc.xml---springmvc的配置,配置处理器映射器、适配器、视图解析器
SqlMapConfig.xml---mybatis的配置文件,配置别名、settings、mapper
- 4.