1:引入pomjava
2:增長生成配置xml:mysql
<?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> <!-- 制定mysql的驅動包的路徑 千萬別放中文路徑下 --> <!--<classPathEntry location="C:\Users\cao\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar" />--> <classPathEntry location="C:\Users\cao\.m2\repository\com\oracle\ojdbc6\11.2.0.1.0\ojdbc6-11.2.0.1.0.jar" /> <!-- 配置數據源和生成的代碼所存放的位置 --> <context id="context1"> <commentGenerator> <property name="suppressAllComments" value="true"/> <property name="suppressDate" value="true"/> </commentGenerator> <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver"--> <!--connectionURL="jdbc:mysql://localhost:3306/test" userId="root"--> <!--password="root" />--> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@101.201.148.185:1521:xx" userId="xxxx" password="xxxxx" /> <!-- !!!! Model Configurations !!!! --> <javaModelGenerator targetPackage="cn.tianjin.unifiedfee.wa.outerweb.entity" targetProject="src/main/java"> <property name="enableSubPackages" value="false"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- !!!! Mapper XML Configurations !!!! --> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!-- !!!! Mapper Interface Configurations !!!! --> <javaClientGenerator targetPackage="cn.tianjin.unifiedfee.wa.outerweb.mapper" targetProject="src/main/java" type="XMLMAPPER"> <property name="enableSubPackages" value="false"/> </javaClientGenerator> <table schema="" tableName="tb_log" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" > </table> </context> </generatorConfiguration>
3:增長java類:web
代碼:
List<String> warnings = new ArrayList<String>(); boolean overwrite = true; File directory = new File("");// 參數爲空 String courseFile = directory.getCanonicalPath(); File configFile = new File(courseFile+"/src/test/java/generatorConfig.xml");//mbg.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);
ok。sql