使用Maven插件生成Mybatis代码

本文详细介绍了如何使用MyBatis Generator自动生成持久层代码,包括配置文件的各个部分及参数说明,帮助开发者快速上手。

<?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>

    <!--maven命令: mvn mybatis-generator:generate-->

    <!--maven插件-->
    <!--<plugin>-->
        <!--<groupId>org.mybatis.generator</groupId>-->
        <!--<artifactId>mybatis-generator-maven-plugin</artifactId>-->
        <!--<version>1.3.5</version>-->
        <!--<configuration>-->
            <!--<verbose>true</verbose>-->
            <!--<overwrite>true</overwrite>-->
        <!--</configuration>-->
    <!--</plugin>-->

    <!-- 数据库驱动包位置 (需要根据自己的路径修改)-->
    <classPathEntry location="C:/Users/Administrator/JavaProjects/generator/mysql-connector-java-5.1.26-bin.jar"/>

    <context id="Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!-- 数据库链接URL、用户名、密码 (定制修改)-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&amp;characterEncoding=utf8"
                        userId="test" password="test"/>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- 生成模型的包名和位置,实体类 -->
        <javaModelGenerator targetPackage="com.zichan360.domain" targetProject="C:/Users/Administrator/git">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- 0、生成的映射文件包名和位置,Mapper文件 -->
        <sqlMapGenerator targetPackage="com.zichan360.mapper" targetProject="C:/Users/Administrator/git">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!--如果生成注解不需要1和2任选一个,一个注解版,一个Xml版Sql -->
        <!-- 1、生成DAO的包名和位置,注解Sql文件, 注解版Mapper文件与SqlProvider在一个文件夹-->
        <javaClientGenerator type="ANNOTATEDMAPPER" targetPackage="com.zichan360.mapper" targetProject="C:/Users/Administrator/git">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- 2、生成DAO的包名和位置,Xml文件 -->
        <!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.zichan360.case_center.mapper.master" targetProject="C:/Users/Administrator/git">-->
            <!--<property name="enableSubPackages" value="true"/>-->
        <!--</javaClientGenerator>-->

        <!-- 要生成那些表(更改tableName和domainObjectName就可以,多个表的话复制table标签在后边排列即可) -->
        <table tableName="acr_invoice" domainObjectName="AcrInvoice"
               enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true"
               enableSelectByExample="true" selectByExampleQueryId="true">
            <generatedKey column="id" sqlStatement="MySql" identity="true" />
        </table><!-- 要生成那些表(更改tableName和domainObjectName就可以,多个表的话复制table标签在后边排列即可) -->
        <table tableName="acr_remittance" domainObjectName="AcrRemittance"
               enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true"
               enableSelectByExample="true" selectByExampleQueryId="true">
            <generatedKey column="id" sqlStatement="MySql" identity="true" />
        </table><!-- 要生成那些表(更改tableName和domainObjectName就可以,多个表的话复制table标签在后边排列即可) -->
        <table tableName="acr_settlement" domainObjectName="AcrSettlement"
               enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true"
               enableSelectByExample="true" selectByExampleQueryId="true">
            <generatedKey column="id" sqlStatement="MySql" identity="true" />
        </table>

    </context>

</generatorConfiguration>

转载于:https://my.oschina.net/mcyy568/blog/810388

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值