Use mybatis-generator generator
The record about how to use this plug-in, first of all declare that I use is springboot.
1.pom file import plug-in
<plugins>
<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.2</version>
<configuration>
<!-- 主要需要改一下配置文件的位置 -->
<configurationFile>generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
This is mainly to note that the profile generatorConfig.xml
location, is my comment that line. I put the pom configuration files and files in the same directory. Also recommended that all do, behind the configuration file can be changed a little less.
2. Configure generatorConfig.xml
Then modify the configuration file, so a few major changes:
- jdbc driver position
- Database connection information
- Entity class, dao, package path and the xml file path.
If your profile generatorConfig.xml
is also on the same level and pom directory, where the file path is not how need to move, change it as long as the package path.
generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!--JDBC驱动jar包的位置,这里就是本地仓库的位置,自己项目配置的mysql驱动-->
<classPathEntry
location="E:\Users\EDZ\.m2\repository\mysql\mysql-connector-java\8.0.18\mysql-connector-java-8.0.18.jar"/>
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="false"/>
</commentGenerator>
<!-- 数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/数据库名?tinyInt1isBit=false"
userId="******"
password="*****"/>
<!-- 实体类 -->
<javaModelGenerator targetPackage="com.power.tools.demo.module.admin.model"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- xml文件 -->
<sqlMapGenerator targetPackage="mapping"
targetProject="./src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- dao层 -->
<javaClientGenerator targetPackage="com.power.tools.demo.module.admin.dao"
targetProject="./src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 这里有几张表就复制几个 -->
<table tableName="t_b_account" domainObjectName="Account"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
3. Run the plug
In front are configured correctly, run the plug-in here just fine.
[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-75izeeeE-1579423353179) (using mybatis-generator generator /1579422447644.png)]
You can see the generated files
[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-Qc5DesvU-1579423353181) (using mybatis-generator generator /1579423337454.png)]
Plug-line look like.
We can see the files generated
there should be a lot of features, if you need some special features, you can go to the official website mybatis look at this plugin Where else can configure.