generator代码逆向工程生成器。
自己现在在用的一个逆向工具,看到CSDN好多要收费,还希望能帮到有用的人。复制过去可以直接拿去用,稍微修改一下
generator.xml
<?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 location="D:\mysql-connector-java-5.1.0-bin.jar" />-->
<context id="Mysql2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"></property>
<property name="suppressAllComments" value="true"></property>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL=""//数据库的路径,下面是账号密码
userId=""
password="">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--实体类文件生成-->
<javaModelGenerator targetPackage="com.sharainy.pojo" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--mapper接口生成-->
<sqlMapGenerator targetPackage="com.sharainy.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--mapper.xml生成-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.sharainy.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!--数据库需要生成的表,只需要修改tabalName对应数据库表-->
<table tableName="geteway" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
</table>
<!-- <table tableName="district" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
</table>
<table tableName="street" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
</table>
<table tableName="type" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
</table>
<table tableName="house" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
</table>
-->
</context>
启动的Util
public static void main(String[] args) {
try {
System.out.println("start generator ...");
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File(MybatisGeneratorUtil.class.getResource("/generator.xml").getFile());//这里写你的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);
System.out.println("干啥啥不行,用起工具第一名!");
} catch (IOException e) {
e.printStackTrace();
} catch (XMLParserException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}