Spring Boot Mybatis-Plus

Mybatis-Plus 是对 Mybatis-Plus 的一些扩充。

在 Spring Boot 中进行集成的时候其实基本上和 mybatis 是一致的。

在你的配置文件中。配置 你的 entity 的存放包路径 和 mapper 的路径。

mybatis-plus.mapper-locations=classpath:/mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
mybatis-plus.typeAliasesPackage=com.sxlq.demo.mybatis.entity
#主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
mybatis-plus.global-config.id-type=2
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
mybatis-plus.global-config.field-strategy=2
mybatis-plus.global-config.db-column-underline=false
#刷新mapper 调试神器
mybatis-plus.global-config.refresh-mapper=true
#数据库大写下划线转换
#mybatis-plus.global-config.capital-mode=true
#序列接口实现类配置
#key-generator: com.baomidou.springboot.xxx
#逻辑删除配置
#logic-delete-value: 0
#logic-not-delete-value: 1
#自定义填充策略接口实现
#meta-object-handler: com.baomidou.springboot.xxx
#自定义SQL注入器
#sql-injector: com.baomidou.springboot.xxx

还需要在启动类上添加一下代码,可以让你的 mapper 注册成为 bean

@MapperScan("com.sxlq.demo.mybatis.dao")

在你的启动类同包下创建一个 SupperMapper

public interface SupperMapper<T> extends BaseMapper<T> { }

你的所有 mapper 都继承这个接口。注意这个接口不要被扫到。

pom 文件添加

		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatisplus-spring-boot-starter</artifactId>
			<version>1.0.5</version>
		</dependency>
		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus</artifactId>
			<version>2.1.7</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
posted @ 2018-11-22 16:44  这块显卡有点冷  阅读(288)  评论(0编辑  收藏  举报