daoresources目录下的pom.xml中添加如下,

    <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.5</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>${mysql.version}</version>
                        <!--            <scope>runtime</scope>-->
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

daoresources目录下的pom.xml中添加如下,新建文件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="DB2Tables"    targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 不希望生成的注释中包含时间戳 -->
            <property name="suppressDate" value="true"/>
            <!-- 是否不生成注释 -->
            <property name="suppressAllComments" value="true"/>
            <!-- 添加 db 表中字段的注释 -->
            <!--            <property name="addRemarkComments" value="true"/>-->

        </commentGenerator>
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/test" userId="root" password="root">
        </jdbcConnection>
        <!-- 数据库类型与java类型转换 -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 生成Model类存放位置 -->
        <javaModelGenerator targetPackage="com.xiaosheng.video.dao.po" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="false"/>
        </javaModelGenerator>
        <!-- 生成映射文件存放位置 -->
        <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources" >
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成Dao类存放位置 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.xiaosheng.video.dao.mapper" targetProject="src/main/java" >
            <property name="enableSubPackages" value="true" />

        </javaClientGenerator>
        <!-- 生成对应表及类名 -->

        <!--        <table tableName="user" domainObjectName="UserPO"-->
        <!--               enableCountByExample="false"-->
        <!--               enableUpdateByExample="false"-->
        <!--               enableDeleteByExample="false"-->
        <!--               enableSelectByExample="false"-->
        <!--               selectByExampleQueryId="false">-->
        <!--        </table>-->

        <table tableName="t_user" domainObjectName="UserPO"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="t_user_info" domainObjectName="UserInfoPO"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

    </context>
</generatorConfiguration>

        <!--打开Terminal,先mvn install 再cd到dao根目录,执行  mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate   会自动生成po,mapper,xml-->

注意其中表名尽量不要和其他数据库重复,不然可能出现bug,我刚刚就生成了三个一样的mapper,
执行的话,

mvn install
cd 到dao根目录
 mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate
分类: javatools

站点统计

  • 文章总数:309 篇
  • 分类总数:19 个
  • 标签总数:191 个
  • 运行天数:1009 天
  • 访问总数:128902 人次

浙公网安备33011302000604

辽ICP备20003309号