6、springboot 集成mybatis
http://www.mybatis.org/mybatis-3/
https://github.com/mybatis/spring-boot-starter
1、添加mybatis 相关依赖
2、在application.properties 设置 mybatis 参数
mybatis 配置参数
|
3、声明Mapper接口: 接口添加@Mapper注解
4、service 实现调用mapper
5、在springboot启动类添加 Mapper扫描组件 @MapperScan("com.chn.frameweb.core.mapper") (重要)
6、 如果不采用@MapperScan 的话,在application.properties中声明 mappers的位置也可以
注意(重要):mybatis 需要配置数据源DataSource,(SqlSessionFactory 工厂类中需要注入 数据库连接池实例 datasource ),在本集成搭建过程中并没有发现配置datasource,
这是因为 mybatis-spring-boot-starter 包含了mybatis-spring-boot-autoconfigure.jar 做了自动配置 ,会自动获取服务里的datasource ,并且自动加载了事务管理包