Spring整合Mybatis
思路:將Mybatis的SqlSessionFactory交給Spring。
SM整合步驟:
1.jar

2.類-表
3.mybatis配置文件conf.xml
4.通過mapper.xml將類、表建立映射關系
5.spring管理SqlSessionFactory
配置spring配置文件:applicationContext.xml
6.使用Spring-MyBatis整合產物開發程序
目標:通過Spring產生Mybatis最終操作需要的動態mapper對象。
(1)DAO層實現類,繼承SqlSessionDaoSupport類,該類提供了一個屬性SqlSession
(2)省略第一種方式中的實現類
直接使用MyBatis提供的實現類org.mybatis.spring.mapper.MapperFactoryBean。
(3)批量處理:批量配置實現類
注意:批量產生mapper對在ioc中的id值默認為接口名,接口名=id,接口名首字母小寫
注解形式的依賴注入
//實現bean @Service("studentService") public class StudentServiceImpl implements IStudentService { //實現ioc中的注入,自動裝配,默認byType @Autowired //根據name來注入 @Qualifier("studao") IStudentDao studentDao; public IStudentDao getStudentDao() { return studentDao; } public void setStudentDao(IStudentDao studentDao) { this.studentDao = studentDao; } }