Spring|6、springboot 集成mybatis
http://www.mybatis.org/mybatis-3/
https://github.com/mybatis/spring-boot-starter
1、添加mybatis 相关依赖
文章图片
2、在application.properties 设置 mybatis 参数
mybatis 配置参数
#########mybatis########### ## 设置mybatis的mapper和model扫描路径 mybatis.mapperLocations=classpath:mapping/*.xml,classpath:mapping/**/*.xml mybatis.typeAliasesPackage=com.chn.frameweb.core.model mybatis.config-location=classpath:mybatis/mybatis.cfg.xml #mapper: 配置mappers路径后,则在接口中不需要添加@Mapper 注解了 #mappers 多个接口时逗号隔开 mapper.mappers=com.chn.frameweb.core.mapper.* mapper.not-empty=false #mapper.identity=MYSQL mapper.identity=ORACLE |
3、声明Mapper接口: 接口添加@Mapper注解
![Spring|6、springboot 集成mybatis](https://img.it610.com/image/info8/6ab740fa33af42008d55424570d2867e.jpg)
文章图片
4、service 实现调用mapper
![Spring|6、springboot 集成mybatis](https://img.it610.com/image/info8/7c9f501040ce4e3ca692b20e103f3f53.jpg)
文章图片
5、在springboot启动类添加 Mapper扫描组件 @MapperScan("com.chn.frameweb.core.mapper") (重要)
![Spring|6、springboot 集成mybatis](https://img.it610.com/image/info8/7841f3f6360c4b01b0095b5ad1dca901.jpg)
文章图片
6、 如果不采用@MapperScan 的话,在application.properties中声明 mappers的位置也可以
![Spring|6、springboot 集成mybatis](https://img.it610.com/image/info8/e067f0508a3244959d8dae216d121add.jpg)
文章图片
注意(重要):mybatis 需要配置数据源DataSource,(SqlSessionFactory 工厂类中需要注入 数据库连接池实例 datasource ),在本集成搭建过程中并没有发现配置datasource,
这是因为 mybatis-spring-boot-starter 包含了mybatis-spring-boot-autoconfigure.jar 做了自动配置 ,会自动获取服务里的datasource ,并且自动加载了事务管理包
【Spring|6、springboot 集成mybatis】
推荐阅读
- 一个人的碎碎念
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- Shell-Bash变量与运算符
- 清明,是追思、是传承、是感恩。
- 牛人进化+|牛人进化+ 按自己的意愿过一生
- Activiti(一)SpringBoot2集成Activiti6
- 七老修复好敏感、角质层薄、红血丝
- 华为旁!大社区、地铁新盘,佳兆业城市广场五期!
- 标签、语法规范、内联框架、超链接、CSS的编写位置、CSS语法、开发工具、块和内联、常用选择器、后代元素选择器、伪类、伪元素。
- 螃蟹和这些食物同吃,轻则腹泻、重则中毒!要小心哦~