MyBatis reverse engineering code

Manually generating the model, mapper and xml files related to MyBatis is a waste of time. It is very convenient to use the mybatis-generator provided by MyBatis to automatically generate according to the database table;

1. Introduce related dependent jar packages

<!--MySQL driver--><dependency>    <groupId>mysql</groupId>    <artifactId>mysql-connector-java</artifactId></dependency><!--MyBatis integrates the initial dependency of the SpringBoot framework--><dependency>    <groupId>org.mybatis.spring.boot</groupId>    <artifactId>mybatis-spring-boot-starter</artifactId>    <version>2.1.1</version></dependency>

Two, add the plug-ins needed to generate the code

<plugins>    <!--Mybatis code automatic generation plug-in-->    <plugin>        <groupId>org.mybatis.generator</groupId>        <artifactId>mybatis-generator-maven-plugin</artifactId>        <version>1.3.6</version>        <configuration>            <!--The location of the configuration file-->            <configurationFile>GeneratorMapper.xml</configurationFile>            <verbose>true</verbose>            <overwrite>true</overwrite>        </configuration>    </plugin>    <!--Springboot project compiled and packaged plug-in-->    <plugin>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-maven-plugin</artifactId>    </plugin></plugins>

3. Configure the GeneratorMapper.xml file and add the file to the project root directory, which is the same level as the pom file

<?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>    <!-- Specify the location of the JDBC driver package to connect to the database, specify the full path to your local machine, and make sure that the jar exists in the local path -->    <classPathEntry location="E:\apache-maven-3.2.5\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar"/>    <!-- Configure table table information content body, targetRuntime specifies the version of MyBatis3 -->    <context id="tables" targetRuntime="MyBatis3">        <!--Serialization-->        <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>        <!--The following plug-ins are required-->        <!--            Return ID after successful insertion           <plugin type="cn.doity.common.generator.plugin.InsertAndReturnKeyPlugin"/>           Paging query function           <plugin type="cn.doity.common.generator.plugin.SelectByPagePlugin"/>           Generate select statement plugin with for update suffix           <plugin type="cn.doity.common.generator.plugin.SelectForUpdatePlugin"/> -->        <!-- Suppress the generation of comments, because the generated comments are all in English, you can prevent it from generating -->        <commentGenerator>            <property name="suppressAllComments" value="true" />        </commentGenerator>        <!-- Configure database connection information -->        <jdbcConnection driverClass="com.mysql.jdbc.Driver"                        connectionURL="jdbc:mysql://127.0.0.1:3306/test"                        userId="root"                        password="root123" >        </jdbcConnection>        <!-- Generate the model class, targetPackage specifies the package name of the model class, targetProject specifies the project under which the generated model is placed in eclipse -->        <javaModelGenerator targetPackage=" com.csnt.spmvc.dao.model "targetProject="src/main/java">            <property name="enableSubPackages" value="false" />            <property name="trimStrings" value="false" />        </javaModelGenerator>        <!-- Generate the Mapper.xml file of MyBatis, targetPackage specifies the package name of the mapper.xml file, and targetProject specifies the project under which the generated mapper.xml is placed in eclipse -->        <sqlMapGenerator targetPackage=" com.csnt.spmvc.dao.mapper "targetProject="src/main/java">            <property name="enableSubPackages" value="false" />        </sqlMapGenerator>        <!-- Generate the Mapper interface class file of MyBatis, targetPackage specifies the package name of the Mapper interface class, and targetProject specifies the project under which the generated Mapper interface is placed in eclipse -->        <javaClientGenerator type="XMLMAPPER" targetPackage=" com.csnt.spmvc.dao.mapper "targetProject="src/main/java">            <property name="enableSubPackages" value="false" />        </javaClientGenerator>        <!-- Database table name and corresponding Java model class name-->        <table tableName="movie"               domainObjectName="Movie"               enableCountByExample="false"               enableUpdateByExample="false"               enableDeleteByExample="false"               enableSelectByExample="false"               selectByExampleQueryId="false"/>        <table tableName="receive_info"               domainObjectName="ReceiveInfo"               enableCountByExample="false"               enableUpdateByExample="false"               enableDeleteByExample="false"               enableSelectByExample="false"               selectByExampleQueryId="false"/>    </context></generatorConfiguration>

Four, generate relevant code

Find the maven column on the right side of the idea project and open Plugins->mybatis-generator

Double-click mybatis-generator:generate, as shown in the figure below: