• 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>
  • 相关阅读:
    售后返修管理软件流程设计图
    Easyui datagrid加载数据时默认全选的问题
    如何做好售后管理之售后返修品管理
    您需要售后返修管理软件的N个理由
    使用软件量化考核售后维修人员业绩?
    如何使用NET Reactor为您的.Net(C#,VB.Net) 源代码加密!
    VS.Net开发必备,让您的代码自动收缩,如何实现!
    vs生成dll,却没有生成相应的lib
    c++、webServices、gsoap、tinyxml、iconv
    gsoap、c++。webservice的client。
  • 原文地址:https://www.cnblogs.com/lantu1989/p/7305317.html
Copyright © 2020-2023  润新知