• mybatis 生成 mapper文件


    package com.util;
    
    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;
    
    /**
     * 描述:
     * <p>
     * author caoxiaoyang
     * date 2021-04-27
     * version
     */
    public class GenUtils {
        public static void main(String[] args) {
            try {
                List<String> warnings = new ArrayList<String>();
                boolean overwrite = true;
                String genCfg = "generatorConfig.xml";
                
                File configFile = new File("D:\generatorConfig.xml");
                ConfigurationParser cp = new ConfigurationParser(warnings);
                Configuration config = null;
                config = cp.parseConfiguration(configFile);
                DefaultShellCallback callback = new DefaultShellCallback(overwrite);
                MyBatisGenerator myBatisGenerator = null;
                myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
                myBatisGenerator.generate(null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    <?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="mysqlTables" targetRuntime="MyBatis3">
    
            <commentGenerator>
                <!-- 是否去除自动生成的注释 true:是 : false:否 -->
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
    
            <!-- 数据库连接 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://127.0.0.1:3306/date?characterEncoding=UTF-8"
                            userId="root"
                            password="123456"/>
            <!--指定生成的类型为java类型,避免数据库中number等类型字段 -->
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false"/>
            </javaTypeResolver>
    
            <!--自动生成的实体的存放包路径-->
            <javaModelGenerator targetPackage="com.pojo" targetProject="d:/">
                <property name="enableSubPackages" value="true"/>
                <property name="trimStrings" value="true"/>
            </javaModelGenerator>
    
            <!--自动生成的*Mapper.xml文件存放路径 -->
            <sqlMapGenerator targetPackage="mappers" targetProject="d:/">
                <property name="enableSubPackages" value="true"/>
            </sqlMapGenerator>
            <!--自动生成的*Mapper.java存放路径 -->
    <!--         <javaClientGenerator type="XMLMAPPER" targetPackage="com.mapper" targetProject="src/main/java">-->
    <!--             <property name="enableSubPackages" value="true"/>-->
    <!--         </javaClientGenerator>-->
    
            <table tableName="table_name" domainObjectName="tableName" enableCountByExample="false" enableUpdateByExample="false"
                   enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
            </table>
        </context>
    </generatorConfiguration>
    姓名:曹晓阳 联系方式:1076675163@qq.com
  • 相关阅读:
    【每日算法】C语言8大经典排序算法(2)
    C++虚函数与纯虚函数的区别
    C++ 运算符优先级列表
    【每日算法】C语言8大经典排序算法(1)
    C++中的友元函数和友元类
    二叉树前序、中序、后序遍历相互求法
    【转】运算符重载的例析
    从一个二级题来看成员函数重载运算符和友元函数重载运算符
    测试用例管理之 TestLink
    【转】关于LoadRunner的迭代
  • 原文地址:https://www.cnblogs.com/CAOXIAOYANG/p/14721008.html
Copyright © 2020-2023  润新知