springboot integrates mybatis reverse engineering solution

Using method of mybatis reverse engineering

Spring boot integrates mybtis reverse engineering. I use the same principle of idea, spring boot, maven and eclipse.

1. Add required plug-ins and jar packages

            <groupId> mysql</groupId>
            <artifactId> mysql-connector-java</artifactId>
            <id>Generate MyBatis Artifacts</id>
        <!--Allow the generated files to be moved -->
        <!-- Is it covered? -->
        <!-- Auto generated configuration -->

2. Add the configuration file "mybatis-generator.xml" in the root directory of the project. The file name must not be wrong, otherwise no exception is found in the report.

Here are the contents of the profile pair

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    <!--mysql Connect to database jar Choose your local location here-->
    <context id="testTables" targetRuntime="MyBatis3">
            <!-- Remove automatically generated comments or not true: Yes, false:no -->
            <property name="suppressAllComments" value="true"/>
        <!--Database connection information: driver class, connection address, user name, password -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test?serverTimezone=UTC" userId="root"
        <!-- default false,hold JDBC DECIMAL and NUMERIC Type resolves to Integer,by true Shi Ba JDBC DECIMAL and
           NUMERIC Type resolves to java.math.BigDecimal -->
            <property name="forceBigDecimals" value="false"/>

        <!-- targetProject:generate PO Class location -->
        <javaModelGenerator targetPackage="com.orangesay.entity"
            <!-- enableSubPackages:Whether to let schema As suffix of package -->
            <property name="enableSubPackages" value="false"/>
            <!-- Spaces before and after values returned from the database are cleaned up -->
            <property name="trimStrings" value="true"/>
        <!-- targetProject:mapper Location of map file generation
           //If maven project is only a separate project, targetProject="src/main/java"
           //If maven project is a sub module project, targetProject = "name of module", for example:
           targetProject="ecps-manager-mapper",Same below-->
        <sqlMapGenerator targetPackage="mapper"
            <!-- enableSubPackages:Whether to let schema As suffix of package -->
            <property name="enableSubPackages" value="false"/>
        <!-- targetPackage: mapper Location of interface generation -->
        <javaClientGenerator type="XMLMAPPER"
            <!-- enableSubPackages:Whether to let schema As package suffix -->
            <property name="enableSubPackages" value="false"/>
        <!-- Specify multiple representations of database tables,More than one can be used. table Label-->
        <table tableName="user"

Note the following:

  • The path of mysql-connector-java-5.1.46.jar is the local absolute path
  • Database connection address, user name and password need to be modified to their own database information
  • The location of pojo class, dao interface and mapper configuration file are all modified to their own
  • The last table tag contains the table name. Multiple tables can be used

3. Run mybatis generator: generate to generate pojo, dao and mapper layers

springboot integrates mybatis reverse engineering and it's finished!!!

Tags: Mybatis MySQL Java Maven

Posted on Sun, 09 Feb 2020 12:55:03 -0500 by michibk