Mybatis-Plus(简称MP)是一个 Mybatis 的增强工具,在 Mybatis 的基础上只做增强不做改变,为简化开发、提高效率而生。(摘自mybatis-plus官网)Mybatis虽然已经给我们提供了很大的方便,但它还是有不足之处,MP的存在就是为了稍稍弥补Mybatis的不足。在我们使用Mybatis时会发现,每当要写一个业务逻辑的时候都要在DAO层写一个方法,再对应一个SQL,即使是简单的条件查询、即使仅仅改变了一个条件都要在DAO层新增一个方法,针对这个问题,MP这样一个框架,一种集Mybatis与Hibernate的优点一起的框架。它提供了Hibernate的单表CURD操作的方便同时,又保留了Mybatis的特性。
1.引入依赖
<!-- mybatis -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<version>${mybatisplus-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.3</version>
</dependency>
2.编辑application.yml
################### mybatis-plus配置 ###################
mybatis-plus:
mapper-locations: classpath:mapping/*Mapper.xml
type-aliases-package: com.wondertek.oes.workbench.manage.model
global-config:
id-type: 0 #0:数据库ID自增 1:用户输入id 2:全局唯一id(IdWorker) 3:全局唯一ID(uuid)
db-column-underline: true #驼峰下划线转换
refresh: true
#capital-mode: true #数据库大写下划线转换
configuration:
map-underscore-to-camel-case: true
cache-enabled: false #配置的缓存的全局开关
log-impl: org.apache.ibatis.logging.log4j.Log4jImpl #打印sql语句,调试用
3.
逆向生成pojo,mapper
创建generatorConfig.xml*(参考上一篇博客)