版本号
框架 | 版本 |
---|---|
spring boot | 2.2.1.RELEASE |
mybatis | 1.2.3 |
mybatis-plus | 2.0.1 |
pagehelper | 1.2.3 |
引入maven依赖
引入相关的依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
添加配置
配置application.yml
mybatis-plus:
mapper-locations: classpath*:mapper/**.xml
#实体扫描,多个package用逗号或者分号分隔
# typeAliasesPackage: com.pm.facade.*.entity
# typeEnumsPackage: com.baomidou.springboot.db.entity.enums
global-config:
db-config:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
id-type: AUTO
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy: not_empty
#驼峰下划线转换
column-underline: true
#数据库大写下划线转换
#capital-mode: true
#逻辑删除配置
logic-delete-value: Y
logic-not-delete-value: N
db-type: mysql
#刷新mapper 调试神器
refresh: true
#自定义填充策略接口实现
#meta-object-handler: com.baomidou.springboot.xxx
#自定义SQL注入器
#sql-injector: com.baomidou.springboot.xxx
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
pagehelper:
reasonable: true # 禁用合理化时
support-methods-arguments: true
params: count=countSql
row-bounds-with-count: true
helper-dialect: mysql
启动类上配置
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//扫包地址
@MapperScan(basePackages = "com.puhua.platform.dao")
@SpringBootApplication
public class PlatformApplication {
public static void main(String[] args) {
SpringApplication.run(PlatformApplication.class, args);
}
}
建议
使用mybais-plus建议使用mybatis-plus-generator逆向工程生成对应的mapper和实体类