Mybatis generator代码生成工具

阅读更多

generatorConfig.xml

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

 

[html]  view plain copy
  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. }  

你可能感兴趣的:(generator)