MybatisCodeGenerator代码生成器

@Mybatis-Plus代码生成器

mybatis-plus依赖

    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.5.1</version>
    </dependency>

    <!--   mybatis-plus代码生成器     -->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-generator</artifactId>
        <version>3.3.1</version>
    </dependency>

.properties配置文件

server.port=8080

# druid
#spring.datasource.druid.master.url=
spring.datasource.druid.master.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true
#spring.datasource.druid.master.username=
spring.datasource.druid.master.username=root
#spring.datasource.druid.master.password=
spring.datasource.druid.master.password=123456
spring.datasource.druid.master.driver-class-name=com.mysql.jdbc.Driver

定义MyBatisCodeGenerator

public class MyBatisCodeGenerator {
    public static void main(String[] args) throws Exception {
        System.out.println("+++++++++generate begin++++++++++");
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true ;
        String url = MyBatisCodeGenerator.class.getResource("/MBG_configuration.xml").getFile();
        File configFile = new File(url);
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
        System.out.println("+++++++++generate writer end+++++++++++");
    }
}

定义MBG_configuration.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>
<!--    <classPathEntry-->
<!--            location="C:/Oracle/Middleware/wlserver_10.3/server/lib/ojdbc6.jar"/>-->
    <context id="my" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="false"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

<!--        <jdbcConnection driverClass="org.postgresql.Driver"-->
<!--                        connectionURL="jdbc:postgresql://127.0.0.1:5432/postgres?useSSL=false"-->
<!--                        userId="gpadmin"-->
<!--                        password="pivotal"/>-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test?useUnicode=true;characterEncoding=utf-8;allowMultiQueries=true;useSSL=false;allowPublicKeyRetrieval=true"
                        userId="root"
                        password="123456"/>

        <javaModelGenerator targetPackage="com.demo.entity"
                            targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>

            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <sqlMapGenerator targetPackage="mapper"
                         targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.demo.mapper"
                             targetProject="src/main/java">

            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>



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

<!--        <table tableName="import_user_errors" domainObjectName="ImportUserErrors"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="organization" domainObjectName="Organization"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="platform_roles" domainObjectName="PlatformRoles"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->

<!--        <table tableName="v_refact_role_resources" domainObjectName="VRefactRoleResource"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->

        <table tableName="test" domainObjectName="test"
               enableCountByExample="true"
               enableUpdateByExample="true" enableDeleteByExample="true"
               enableSelectByExample="true" selectByExampleQueryId="true"
               enableInsert="true" enableUpdateByPrimaryKey="true"
               enableDeleteByPrimaryKey="true">
            <!--<columnRenamingRule searchString="^D_"
                                replaceString=""/>-->
        </table>
<!--        <table tableName="users" domainObjectName="User"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->

<!--        <table tableName="projects" domainObjectName="Project"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="resources" domainObjectName="Resource"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="role_resources" domainObjectName="RoleResource"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="roles" domainObjectName="Role"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="system_connections" domainObjectName="SystemConnection"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="systems" domainObjectName="System"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="user_organization" domainObjectName="UserOrganization"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="user_resources" domainObjectName="UserResource"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="user_roles" domainObjectName="UserRole"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="user_system" domainObjectName="UserSystem"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->

<!--        <table tableName="data_models" domainObjectName="DataModel"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="data_model_detail" domainObjectName="DataModelDetail"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->
<!--        <table tableName="users" domainObjectName="User"-->
<!--               enableCountByExample="true"-->
<!--               enableUpdateByExample="true" enableDeleteByExample="true"-->
<!--               enableSelectByExample="true" selectByExampleQueryId="true"-->
<!--               enableInsert="true" enableUpdateByPrimaryKey="true"-->
<!--               enableDeleteByPrimaryKey="true">-->
<!--            &lt;!&ndash;<columnRenamingRule searchString="^D_"-->
<!--                                replaceString=""/>&ndash;&gt;-->
<!--        </table>-->


    </context>
</generatorConfiguration>

链接: link.

Alt

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值