• mybatis 逆向工程


    根据实际情况添加相应的数据库驱动jar包

    package util;
    
    import java.io.File;
    import java.io.IOException;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.mybatis.generator.api.MyBatisGenerator;
    import org.mybatis.generator.config.Configuration;
    import org.mybatis.generator.config.xml.ConfigurationParser;
    import org.mybatis.generator.exception.InvalidConfigurationException;
    import org.mybatis.generator.exception.XMLParserException;
    import org.mybatis.generator.internal.DefaultShellCallback;
    
    /** 
     * @author lf 
     */
    public class MyBatisGeneratorTool {
    
        public static void main(String[] args) {
            List<String> a = new ArrayList<String>();
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            // 配置文件的路径
            String genCfg = "/xml/generator.xml";
            File configFile = new File(MyBatisGeneratorTool.class.getResource(genCfg).getFile());
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = null;
            try {
                config = cp.parseConfiguration(configFile);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XMLParserException e) {
                e.printStackTrace();
            }
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = null;
            try {
                myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            } catch (InvalidConfigurationException e) {
                e.printStackTrace();
            }
            try {
                myBatisGenerator.generate(null);
                System.out.println("文件生成成功!!!!");
            } catch (SQLException e) {
                System.out.println("文件生成失败!!!!");
                e.printStackTrace();
            } catch (IOException e) {
                System.out.println("文件生成失败!!!!");
                e.printStackTrace();
            } catch (InterruptedException e) {
                System.out.println("文件生成失败!!!!");
                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>
        <!-- 配置mybatis-generator-core.jar所在的目录,本地workspace目录 -->
        <classPathEntry
            location="D:workWorkSpacesMyEclipse_Professional_2014generatorlibmybatis-generator-core-1.3.1.jar" />
        <context id="MySqlTables" targetRuntime="MyBatis3">
            <!-- <plugin
                type="com.nbesoft.framework.mybatis.util.MyBatisPaginationPlugin">
            </plugin> -->
            <!-- 关闭注释信息 -->
            <commentGenerator>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://localhost:13306/lf"
                userId="zlf" password="zlf">
            </jdbcConnection>
            
            <!-- 类型转换 -->  
            <javaTypeResolver>
                <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
            
            <!-- model的配置 -->
            <!-- targetProject的目录配置成本地机器的workspace -->
            <javaModelGenerator targetPackage="com.mapper.model"
        targetProject="D:workWorkSpacesMyEclipse_Professional_2014generatorsrc">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
    
            <!-- mybatis的xml的配置 -->
            <sqlMapGenerator targetPackage="com.mapper.xml"
                targetProject="D:workWorkSpacesMyEclipse_Professional_2014generatorsrc">
                <property name="enableSubPackages" value="false" />
            </sqlMapGenerator>
    
            <!-- mapper的配置 -->
            <javaClientGenerator type="XMLMAPPER"
                targetPackage="com.mapper"
                targetProject="D:workWorkSpacesMyEclipse_Professional_2014generatorsrc">
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
    
            <!-- tableName对应的数据库表名, domainObjectName对应程序中的实体类名 -->
            <!-- <table tableName="T_CRMSRV_CUSTINFO" domainObjectName="CustInfo"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false" >
                忽略列,不生成bean 字段  
                <ignoreColumn column="FRED" />  
                指定列的java数据类型  
                <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />  
            </table> -->
            
            <!-- <table tableName="ROLE" domainObjectName="Role"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false" />
    
            <table tableName="USER" domainObjectName="User"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false" />
            
            <table tableName="USER_ROLE" domainObjectName="UserRole"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false" /> -->
            <table tableName="BSD_USER" domainObjectName="BsdUser"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false" />
        </context>
    </generatorConfiguration>
  • 相关阅读:
    IP地址和进制转换
    Cisco交换机常见配置
    macOS上的autoreconf错误导致无法安装问题
    LG P5147 随机数生成器
    LG P1879 [USACO06NOV]Corn Fields G
    LG P5017 [NOIP2018]摆渡车
    mysql触发器trigger详解
    MybatisPuls中QueryWrapper的select、update的用法
    @Transactional各属性详解
    Linux如何查看进程、杀死进程、启动进程等常用命令(包括常用的命令,如查看文件,修改文件读写权限、寻找文件等)
  • 原文地址:https://www.cnblogs.com/lantu1989/p/7305317.html
Copyright © 2020-2023  润新知