Mybatis Generator tool
在我们开启一个新项目的研发后,通常要编写很多的entity/pojo/dto/mapper/dao...
, 大多研发兄弟们都会抱怨,为什么我要重复写CRUD
? 我们为了避免编写一些不必要的重复代码,这节给大家介绍介绍使用一个开源工具,来帮助我们从这种简单枯燥的编码中解救出来。隆重有请: MyBatis通用Mapper4
通用Mapper都可以极大的方便开发人员。可以随意的按照自己的需要选择通用方法,还可以很方便的开发自己的通用方法。
极其方便的使用MyBatis单表的增删改查。
支持单表操作,不支持通用的多表联合查询。
通用 Mapper 支持 Mybatis-3.2.4 及以上版本。
Tips:
各位技术同仁一定要有版本意识哦~
Let's code!
Create mybatis-generator-tool Module
参考上一节中的Module创建mybatis-generator-tool
.
- 添加依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>expensive-shop</artifactId>
<groupId>com.life-runner</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mybatis-generator-tool</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!--springboot 构建可执行fat jars必须的插件,如不添加,在生产环境会有问题-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<!-- 设置配置文件路径 -->
<configurationFile>
${basedir}/src/main/resources/generator/generatorConfig.xml
</configurationFile>
<!--允许覆盖-->
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<!-- mysql8 驱动-->
<dependency&