本文章僅供小編學(xué)習(xí)使用,如有侵犯他人版權(quán),請聯(lián)系小編撤回或刪除
官方文檔:MyBatis-Plus
pom.xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.1.2</version>
</dependency>
配置
- 配置
@MapperScan
注解
@SpringBootApplication
@MapperScan("com.baomidou.mybatisplus.samples.quickstart.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(QuickStartApplication.class, args);
}
}
- 配置 分頁插件
/**
* @liuzongqiang
* @since 2019-07-16
*/
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
/**
* 分頁插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://39.98.172.65:9001/fine_admin?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true
username: xxxxx
password: xxxxx
mybatis-plus:
# 掃描mapper.xml文件
mapper-locations: classpath:/mapper/*Mapper.xml
# 掃描實體類
typeAliasesPackage: com.example.springbootmybatisplus.entity
# 主鍵類型
global-config:
#0:"數(shù)據(jù)庫ID自增", 1:"用戶輸入ID",2:"全局唯一ID (數(shù)字類型唯一ID)", 3:"全局唯一ID UUID";
id-type: 0
#字段策略 0:"忽略判斷",1:"非 NULL 判斷"),2:"非空判斷"
field-strategy: 0
#駝峰下劃線轉(zhuǎn)換
db-column-underline: true
#刷新mapper 調(diào)試神器
refresh-mapper: true
#數(shù)據(jù)庫大寫下劃線轉(zhuǎn)換
#capital-mode: true
#自定義SQL注入器
configuration:
map-underscore-to-camel-case: true
cache-enabled: true
application.properties寫法
#應(yīng)用端口號
server.port=8010
#freemarker 默認(rèn)文件后綴
spring.freemarker.suffix=.html
#數(shù)據(jù)庫設(shè)置
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root
#mybatis plus 設(shè)置
mybatis-plus.mapper-locations=classpath:/mapper/*Mapper.xml
#實體掃描糕非,多個package用逗號或者分號分隔
mybatis-plus.typeAliasesPackage=cn.xiaojf.springboot.mybatisplus.entity
#主鍵類型 0:"數(shù)據(jù)庫ID自增", 1:"用戶輸入ID",2:"全局唯一ID (數(shù)字類型唯一ID)", 3:"全局唯一ID UUID";
mybatis-plus.global-config.id-type=2
#字段策略 0:"忽略判斷",1:"非 NULL 判斷"),2:"非空判斷"
mybatis-plus.global-config.field-strategy=2
#駝峰下劃線轉(zhuǎn)換
mybatis-plus.global-config.db-column-underline=true
#刷新mapper 調(diào)試神器
mybatis-plus.global-config.refresh-mapper=true
#數(shù)據(jù)庫大寫下劃線轉(zhuǎn)換
#mybatis-plus.global-config.capital-mode=true
#序列接口實現(xiàn)類配置
#mybatis-plus.global-config.key-generator=com.baomidou.springboot.xxx
#邏輯刪除配置
mybatis-plus.global-config.logic-delete-value=0
mybatis-plus.global-config.logic-not-delete-value=1
#自定義填充策略接口實現(xiàn)
#mybatis-plus.global-config.meta-object-handler=com.baomidou.springboot.xxx
#自定義SQL注入器
#mybatis-plus.global-config.sql-injector=com.baomidou.springboot.xxx
mybatis-plus.configuration.map-underscore-to-camel-case=true
mybatis-plus.configuration.cache-enabled=false