Mybatis-generator自动生成

第一步:导入架包

 <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.7</version>
                <dependencies>
                    <dependency>
                        <groupId>org.mariadb.jdbc</groupId>
                        <artifactId>mariadb-java-client</artifactId>
                        <version>2.3.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

第二步:在resources目录下创建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>

    <context id="xxx" targetRuntime="MyBatis3Simple">


        <commentGenerator>
            <property name="suppressDate" value="true" />
        </commentGenerator>
        <!-- 数据库连接 -->
        <jdbcConnection driverClass="org.mariadb.jdbc.Driver"
                        connectionURL="jdbc:mariadb://localhost/stu"
                        userId="root" password="123456">
        </jdbcConnection>

        <!-- Model生成规则 -->
        <javaModelGenerator targetPackage="com.wbg.entity" targetProject="src/main/java">
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mapper"  targetProject="src/main/resources"/>
        <!-- dao 规则 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.wbg.dao"  targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <table tableName="%">
            <generatedKey column="id" sqlStatement="Mysql"/>
        </table>
    </context>
</generatorConfiguration>

第三步:启动

ok

 

posted @ 2018-10-19 15:04  韦邦杠  阅读(345)  评论(0编辑  收藏  举报