springboot快速整合mybatis
1. build.gradle
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2')
//compile group: 'com.alibaba', name: 'druid', version: '1.1.10'
}2. application.yml
3. application.java
4. dao
5. po
6. test
7. 说明:
可以不用配置连接池,boot2默认自带hikari连接池,不用引用连接池的jar包,也不用配置type
可以不用配置
@EnableTransactionManagement,默认启动最小配置有两种方式开启mybatis
在每一个dao上加
@mapper注解在启动类上加注解指定dao包
@MapperScan("com.example.demo.dao")
配置下划线和驼峰命名自动转化
使用注解的方式,别名配置不是很重要,但是建议还是配置上的好
sql语句拦截器配置,配置到yml文件中好像还不支持自定的拦截器,实例化拦截器,会自动注册的
Last updated
Was this helpful?