- 前言
- 集成依赖
- 配置yml
- 高级语法
在上文中已经对于spring框架下的Mybatis进行了配置,现在市场上面已经常用到分布式,那么起步基本都用开箱即用的SpringBoot 配置文件进行配置。
其实对于SpringBoot而言约定大于配置,更加方便配置。只需要几行代码就可以把Mybatis集成进去,由上文中的Mysql进行查询,建立jdbc然后对于查询到的数据由两种方式映射,一种是自动化配置,也就是需要再集成一份Mybatis-plus对于此篇文章我就不在赘述,下面我再把Mybatis-Plus 再单开一篇。
对于此,只能用Mybatis 的Xml进行写,其实在开发过程中,基本后端都是增删改查,如果需要分页可以手写,不过有个小框架,大家可以用一下, 也就是Help-page。也是对于Mysql的查询语句进行sql拦截然后再拼接的。框架比较小,大家可以直接看源码。
集成依赖配置ymlmysql mysql-connector-java runtime org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2 com.github.pagehelper pagehelper-spring-boot-starter ${pagehelper-version}
有时候是properties 一个是扁平化,一个是通过 . 分割。不影响
# 数据库配置
spring:
datasource:
url: jdbc:mysql://localhost:3306/ 库?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
username: root
password: 123456
# 映射配置
mybatis:
# 如果有配置文件,详情可以找一下我写的 mybtis 配置的配置意义
config-location: classpath:mybatis-config.xml
# 你把xml文件配置在哪里就找对应资源下的 包下面
mapperLocations: classpath:mapper/*.xml
# 小框架 pagehelper 依赖在上面
pagehelper:
helperDialect:mysql
reasonable:false
supportMethodsArguments:true
params:count=countSql
xml 模板都是一样的照抄就可以了
确保Mapper 包被扫描到
@SpringBootApplication(scanbasePackages = {"com.xxxx.xxx"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
高级语法
mybatis高级语法
这里面比较全,我就不粘过来了。 有什么不明白再交流



