zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    计算机视觉--语义分割
    对团队成员公开感谢
    韩昊20191031-1 每周例行报告
    韩昊20191024-1 每周例行报告
    韩昊20191017-1 每周例行报告
    TensorFlow在windows 下的安装
    20191010-2 每周例行报告
    韩昊 20190919-1 每周例行报告
    韩昊 20190919-4 单元测试,结对
    2505-springboot使用spring.profiles.active来分区配置
  • 原文地址:https://www.cnblogs.com/CAOXIAOYANG/p/14721008.html
Copyright © 2011-2022 走看看