• 利用mybatis-generator生成po


    import java.io.File;
    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.internal.DefaultShellCallback;
    
    
    
    public class AutoCreateBean {
        public static void main(String[] args) {
             String path = AutoCreateBean.class.getResource("").toString();  
            if (path != null)  
                {  
                    path = path.substring(6,path.length());//如果是windwos将5变成6  
                    if(path.indexOf("%e9%83%ad%e7%ab%af%e7%ab%af") !=-1){
                        path = path.replace("%e9%83%ad%e7%ab%af%e7%ab%af", "郭端端");
                    }
                    if(path.indexOf("%20")!=-1){
                        path = path.replaceAll("%20", " ") ; //本地包含空格的注意替换
                }
                    System.out.println("current path :" + path);  
                }
            try{
              List<String> warnings = new ArrayList<String>();  
              boolean overwrite = true;  
              File configFile = new File(path+"generator.xml");//获取项目路径,在generator.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); 
            }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>
       
        <!-- classPathEntry:数据库的JDBC驱动的jar包地址-->  
        <classPathEntry location="D:/repository/mysql/mysql-connector-java/5.1.13/mysql-connector-java-5.1.13-bin.jar" />
        <context id="openshopsqlSessionFactory" targetRuntime="MyBatis3">
    
            <commentGenerator>
                <property name="suppressDate" value="true" />
                <property name="suppressAllComments" value="true"/>
            </commentGenerator>
      
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://10.19.105.184:3306/wms" userId="ggs"
                password="ZPIOSVYLXMNI">
            </jdbcConnection>
         <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->  
    <!--        <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" -->
    <!--             connectionURL="jdbc:oracle:thin:@10.19.105.113:1521:orcl" userId="MWS" -->
    <!--             password="MWS2015"> -->
    <!--         </jdbcConnection> -->
    
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
             <!-- targetProject:自动生成javaBean代码的位置 --> 
            <javaModelGenerator targetPackage="com.yunda.inter"
                targetProject="D:/workspace/">
                <property name="enableSubPackages" value="true" />
                <!-- 从数据库返回的值被清理前后的空格  -->   
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
            
            <!-- xml文件 自动生成mapper.xml代码位置-->
            <!-- enableSubPackages:是否让schema作为包的后缀 -->  
            <sqlMapGenerator targetPackage="com.yunda.inter"
                targetProject="D:/workspace/">
                <property name="enableSubPackages" value="true" />
            </sqlMapGenerator>
            
             <!-- 自动生成mapper接口代码位置-->
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.yunda.inter" 
                 targetProject="D:/workspace/">
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
             <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->  
             <!--如果想要生成一个demo,则enableCountByExample设为true  -->
            <table tableName="riv_owner_tx_type" domainObjectName="RivOwnerTxType" 
            enableCountByExample="false" 
            enableUpdateByExample="false" 
            enableDeleteByExample="false" 
            enableSelectByExample="false" 
            selectByExampleQueryId="false" />
        
        </context>
    </generatorConfiguration> 

    mybatis-generator-core-1.3.2.jar

  • 相关阅读:
    sql分页查询
    SQL语句优化技术分析
    大型数据库的设计原则与开发技巧
    Microsoft SharePoint Server 2010 的新增功能
    Installing SharePoint 2010 on Windows 7
    Missing the ManageContent and structure in MOSS 2010
    Simple SharePoint 2010 + Silverlight + Client Object Model Example
    SharePoint 2010 Central AdminCreate/Extend Web Application button on Ribbon are disabled
    利用SharePoint Designer 修改列表页面实例
    数据库设计中的14个技巧
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/6553877.html
Copyright © 2020-2023  润新知