`

Mybatis generator代码生成工具

阅读更多

generatorConfig.xml

[html] view plaincopy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE generatorConfiguration  
  3.   PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
  4.   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">  
  5.   
  6. <generatorConfiguration>  
  7.     <classPathEntry  
  8.         location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.18\mysql-connector-java-5.1.18.jar" />  
  9. <!-- MyBatis3,Ibatis2Java5 -->  
  10.     <context id="DB2Tables" targetRuntime="MyBatis3">  
  11. <!--         <plugin type="org.leef.db.mybatis.plugin.PaginationPlugin" /> -->  
  12.   
  13.         <commentGenerator>  
  14.             <property name="suppressDate" value="true" />  
  15.             <property name="suppressAllComments" value="true" />  
  16.         </commentGenerator>  
  17.   
  18.         <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
  19.             connectionURL="jdbc:mysql://localhost/ManagerPlatform" userId="root"  
  20.             password="123456">  
  21.         </jdbcConnection>  
  22.   
  23.         <javaTypeResolver>  
  24.             <property name="forceBigDecimals" value="false" />  
  25.         </javaTypeResolver>  
  26.   
  27.         <javaModelGenerator targetPackage="com.bingya.model"  
  28.             targetProject="src/main/java">  
  29.             <property name="enableSubPackages" value="true" />  
  30.             <property name="trimStrings" value="true" />  
  31.         </javaModelGenerator>  
  32.   
  33.         <sqlMapGenerator targetPackage="com.bingya.dao"  
  34.             targetProject="src/main/java">  
  35.             <property name="enableSubPackages" value="true" />  
  36.         </sqlMapGenerator>  
  37.   
  38.         <javaClientGenerator type="XMLMAPPER"  
  39.             targetPackage="com.bingya.dao" targetProject="src/main/java">  
  40.             <property name="enableSubPackages" value="true" />  
  41.         </javaClientGenerator>  
  42.   
  43. <!--         <table tableName="T_Article" domainObjectName="Tarticle"> -->  
  44. <!--         </table> -->  
  45.   
  46. <!--         <table tableName="T_Category" domainObjectName="TCategory"> -->  
  47. <!--         </table> -->  
  48.           
  49. <!--         <table tableName="T_Asset" domainObjectName="Tasset"> -->  
  50. <!--         </table> -->  
  51.           
  52.         <table tableName="users" domainObjectName="Users">  
  53.         </table>  
  54.           
  55.         <table tableName="authorities" domainObjectName="Authorities">  
  56.         </table>  
  57.   
  58.     </context>  
  59. </generatorConfiguration>  

 

[html] view plaincopy
  1. import java.io.File;  
  2. import java.io.IOException;  
  3. import java.sql.SQLException;  
  4. import java.util.ArrayList;  
  5. import java.util.List;  
  6.   
  7. import org.mybatis.generator.api.MyBatisGenerator;  
  8. import org.mybatis.generator.config.Configuration;  
  9. import org.mybatis.generator.config.xml.ConfigurationParser;  
  10. import org.mybatis.generator.exception.InvalidConfigurationException;  
  11. import org.mybatis.generator.exception.XMLParserException;  
  12. import org.mybatis.generator.internal.DefaultShellCallback;  
  13.   
  14. public class MBGenerator {  
  15.   
  16.     /**  
  17.      * @param args  
  18.      * @throws XMLParserException  
  19.      * @throws IOException  
  20.      * @throws InvalidConfigurationException  
  21.      * @throws InterruptedException  
  22.      * @throws SQLException  
  23.      */  
  24.     public static void main(String[] args) throws IOException,  
  25.             XMLParserException, InvalidConfigurationException, SQLException,  
  26.             InterruptedException {  
  27.         List<String> warnings = new ArrayList<String>();  
  28.         boolean overwrite = true;  
  29.         File directory = new File(".");  
  30.         File configFile = new File(directory.getCanonicalPath()  
  31.                 + File.separator + "src" + File.separator  
  32.                 + "generatorConfig.xml");  
  33.         ConfigurationParser cp = new ConfigurationParser(warnings);  
  34.         Configuration config = cp.parseConfiguration(configFile);  
  35.         DefaultShellCallback callback = new DefaultShellCallback(overwrite);  
  36.         MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,  
  37.                 callback, warnings);  
  38.         myBatisGenerator.generate(null);  
  39.         System.out.println("success");  
  40.     }  
  41.   
  42. }  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics