MyBatis逆向工程

4 篇文章 0 订阅

MyBatis逆向工程

导入jar包:

mybatis-generator-core.xxx.jar

mbg.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="suppressAllComments" value="true" />
        </commentGenerator>
        <!-- 配置数据库连接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/appinfodb"
                        userId="root"
                        password="root">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- 指定javaBean生成的位置 -->
        <javaModelGenerator targetPackage="cn.test.entity"
                            targetProject=".\src">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!--指定sql映射文件生成的位置 -->
        <sqlMapGenerator targetPackage="cn.test.dao.mapper" targetProject=".\src">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!-- 指定dao接口生成的位置,mapper接口 -->
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="cn.test.dao" targetProject=".\src">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <!-- table指定每个表的生成策略 -->
        <!--tableName:数据库表名 domainObjectName:生成实体类名 -->
        <table tableName="ad_promotion" domainObjectName="AdPromotion"
        <!--不生成example-->
        enableCountByExample="false"
        enableUpdateByExample="false"
        enableDeleteByExample="false"
        enableSelectByExample="false"
        selectByExampleQueryId="false"></table>
        <table tableName="app_category" domainObjectName="AppCategory"></table>
        <table tableName="app_info" domainObjectName="AppInfo" ></table>
        <table tableName="app_version" domainObjectName="AppVersion" ></table>
        <table tableName="backend_user" domainObjectName="BackendUser"></table>
        <table tableName="data_dictionary" domainObjectName="DataDictionary"></table>
        <table tableName="dev_user" domainObjectName="DevUser" ></table>
    </context>
</generatorConfiguration>

执行代码

 public void MyBatisReverse() throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
        List<String> warnings = new ArrayList<String>();
        File configFile = new File("mbg.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
                callback, warnings);
        myBatisGenerator.generate(null);
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值