• Mybatis逆向工程需要的配置文件和生成器(xml + java)


    1、配置文件 mbg.xml(放在src同级目录下)

    <?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>
    
        <!--
            targetRuntime 可以设置生成的版本
            MyBatis3       豪华版本
            MyBatis3Simple CRUD操作
        -->
        <context id="DB2Tables" targetRuntime="MyBatis3">
            <!--去掉全部注释-->
            <commentGenerator>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
    
            <!--
               修改数据库的四个连接属性
           -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/mbg"
                            userId="root"
                            password="root">
            </jdbcConnection>
    
            <javaTypeResolver >
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
            <!--
                  javaModelGenerator生成javaBean
                       targetPackage指定生成的包
                       targetProject指定生成的项目位置
           -->
            <javaModelGenerator targetPackage="com.atguigu.pojo"
                                targetProject=".MyBatis03_mbgsrc">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
    
            <!--
                sqlMapGenerator标签是生成mapper.xml配置信息
                        targetPackage指定生成的包
                        targetProject指定生成的项目位置
            -->
            <sqlMapGenerator targetPackage="com.atguigu.mapper"  targetProject=".MyBatis03_mbgsrc">
                <property name="enableSubPackages" value="true" />
            </sqlMapGenerator>
    
            <!--
               javaClientGenerator生成mapper接口
                       targetPackage指定生成的包
                       targetProject指定生成的项目位置
           -->
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.atguigu.mapper"
                                 targetProject=".MyBatis03_mbgsrc">
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
    
            <table tableName="t_user" domainObjectName="User" ></table>
            <table tableName="t_book" domainObjectName="Book" ></table>
        </context>
    </generatorConfiguration>
    

    2、生成器Runner.java

    import org.mybatis.generator.api.MyBatisGenerator;
    import org.mybatis.generator.config.Configuration;
    import org.mybatis.generator.config.xml.ConfigurationParser;
    import org.mybatis.generator.internal.DefaultShellCallback;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Runner {
        public static void main(String[] args) throws Exception {
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            File configFile = new File("MyBatis03_mbg/mbg.xml");
            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);
        }
    }
    
  • 相关阅读:
    http 301 和 302的区别
    移动端与PHP服务端接口通信流程设计(增强版)
    导出大量数据到excel表
    c#中两种不同的存储过程调用与比较
    sql存储过程几个简单例子
    高级搜索指令
    SEO 百度后台主动推送链接
    C#利用Web Service实现短信发送(转)
    webservice测试实例
    克服演讲紧张的10个技巧
  • 原文地址:https://www.cnblogs.com/iris-/p/13683893.html
Copyright © 2020-2023  润新知