mybatis generated automatically mapper, dao entity file and

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/red_sheeps/article/details/88353052

mybatisCode development is commonly used ORM framework, but three types of commonly used files by manually generate very cumbersome, it could lead to a misallocation of error (because it is a dynamic proxy implementation, use and does not complain at compile time) runtime, run-time error sometimes the error is very broad, it is difficult to locate specific reasons.
Benpian provide project uses generation method, for your reference.

generatorConfig.xml resolve

Document generatorConfig.xmlreads as follows

<?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>
   <!--配置mysql连接jar包-->
    <classPathEntry
            location="C:\Users\aaaaaa\.m2\repository\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar"/>
    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--mysql连接信息-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test"
                        userId="test" password="test">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成的entity存放路径-->
        <javaModelGenerator targetPackage="com.test.entity" targetProject="D:\code\admin-service\src\main\java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成的mapper.xml存放路径-->
        <sqlMapGenerator targetPackage="mybatis.app" targetProject="D:\code\admin-service\src\main\resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--生成的dao文件存放路径-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dao"
                             targetProject="D:\code\admin-service\src\main\java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

<!--表信息-->
        <table tableName="test_info" domainObjectName="TestInfo" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
    </context>
</generatorConfiguration>

pom file to add plugin

<build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>

run

Double-click to run
Running success!
Successful operation

to sum up

工欲善其事必先利其器. In fact, long before it has been so used, but never settle down. Recently also to introduce this new colleagues, everyone says it again is too much trouble, or write a record, and then was asked a direct link to him, they used to go.

Guess you like

Origin blog.csdn.net/red_sheeps/article/details/88353052