zheng-ucenter的GeneratorConfig.xml自动生成
This commit is contained in:
parent
267f963cab
commit
7d47f762f5
|
@ -1,13 +0,0 @@
|
|||
package com.zheng.ucenter.dao;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.zheng.ucenter.dao;
|
||||
|
||||
import com.zheng.common.util.MybatisGeneratorConfigUtil;
|
||||
import com.zheng.common.util.PropertiesFileUtil;
|
||||
|
||||
/**
|
||||
* 代码生成类
|
||||
* Created by ZhangShuzheng on 2017/1/10.
|
||||
*/
|
||||
public class Generator {
|
||||
|
||||
// 根据命名规范,只修改此常量值即可
|
||||
private static String MODULE_PREFIX_NAME = "ucenter";
|
||||
private static String JDBC_DRIVER = PropertiesFileUtil.getInstance("jdbc").get("jdbc.driver");
|
||||
private static String JDBC_URL = PropertiesFileUtil.getInstance("jdbc").get("jdbc.url");
|
||||
private static String JDBC_USERNAME= PropertiesFileUtil.getInstance("jdbc").get("jdbc.username");
|
||||
private static String JDBC_PASSWORD = PropertiesFileUtil.getInstance("jdbc").get("jdbc.password");
|
||||
|
||||
/**
|
||||
* 根据模板生成generatorConfig.xml文件
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MybatisGeneratorConfigUtil.generator(JDBC_DRIVER, JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD, MODULE_PREFIX_NAME);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,63 +2,67 @@
|
|||
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
|
||||
<generatorConfiguration>
|
||||
|
||||
<!-- 配置文件 -->
|
||||
<properties resource="jdbc.properties"></properties>
|
||||
<!-- 配置文件 -->
|
||||
<properties resource="jdbc.properties"></properties>
|
||||
|
||||
<!-- mysql驱动包 -->
|
||||
<classPathEntry location="${classPathEntry}" />
|
||||
<!-- mysql驱动包 -->
|
||||
<classPathEntry location="${classPathEntry}" />
|
||||
|
||||
<context id="context" targetRuntime="MyBatis3">
|
||||
<context id="context" targetRuntime="MyBatis3">
|
||||
|
||||
<property name="javaFileEncoding" value="UTF-8"/>
|
||||
<property name="javaFileEncoding" value="UTF-8"/>
|
||||
|
||||
<!-- 由于beginningDelimiter和endingDelimiter的默认值为双引号("),在Mysql中不能这么写,所以还要将这两个默认值改为**反单引号(`)**,配置如下: -->
|
||||
<property name="beginningDelimiter" value=""/>
|
||||
<property name="endingDelimiter" value=""/>
|
||||
<!-- 由于beginningDelimiter和endingDelimiter的默认值为双引号("),在Mysql中不能这么写,所以还要将这两个默认值改为**反单引号(`)**,配置如下: -->
|
||||
<property name="beginningDelimiter" value=""/>
|
||||
<property name="endingDelimiter" value=""/>
|
||||
|
||||
<!-- 为生成的Java模型创建一个toString方法 -->
|
||||
<!-- 为生成的Java模型创建一个toString方法 -->
|
||||
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
|
||||
|
||||
<!-- 为生成的Java模型类添加序列化接口,并生成serialVersionUID字段 -->
|
||||
<plugin type="com.zheng.common.plugin.SerializablePlugin">
|
||||
<property name="suppressJavaInterface" value="false"/>
|
||||
</plugin>
|
||||
<!-- 为生成的Java模型类添加序列化接口,并生成serialVersionUID字段 -->
|
||||
<plugin type="com.zheng.common.plugin.SerializablePlugin">
|
||||
<property name="suppressJavaInterface" value="false"/>
|
||||
</plugin>
|
||||
|
||||
<!-- 生成一个新的selectByExample方法,这个方法可以接受一个RowBounds参数,主要用来实现分页 -->
|
||||
<!-- 生成一个新的selectByExample方法,这个方法可以接受一个RowBounds参数,主要用来实现分页 -->
|
||||
<plugin type="com.zheng.common.plugin.PaginationPlugin"></plugin>
|
||||
|
||||
<!-- 生成在XML中的<cache>元素 -->
|
||||
<plugin type="org.mybatis.generator.plugins.CachePlugin"></plugin>
|
||||
<!-- 生成在XML中的<cache>元素 -->
|
||||
<plugin type="org.mybatis.generator.plugins.CachePlugin">
|
||||
<!-- 使用ehcache -->
|
||||
<property name="cache_type" value="org.mybatis.caches.ehcache.LoggingEhcache" />
|
||||
<!-- 内置cache配置 -->
|
||||
<!--
|
||||
<property name="cache_eviction" value="LRU" />
|
||||
<property name="cache_flushInterval" value="60000" />
|
||||
<property name="cache_readOnly" value="true" />
|
||||
<property name="cache_size" value="1024" />
|
||||
-->
|
||||
</plugin>
|
||||
|
||||
<!-- Java模型生成equals和hashcode方法 -->
|
||||
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>
|
||||
<!-- Java模型生成equals和hashcode方法 -->
|
||||
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>
|
||||
|
||||
<!-- 生成的代码去掉注释 -->
|
||||
<commentGenerator>
|
||||
<property name="suppressAllComments" value="true" />
|
||||
</commentGenerator>
|
||||
<!-- 生成的代码去掉注释 -->
|
||||
<commentGenerator>
|
||||
<property name="suppressAllComments" value="true" />
|
||||
</commentGenerator>
|
||||
|
||||
<!-- 数据库连接 -->
|
||||
<jdbcConnection driverClass="${jdbc.driver}"
|
||||
connectionURL="${jdbc.url}"
|
||||
userId="${jdbc.username}"
|
||||
password="${jdbc.password}" />
|
||||
<!-- 数据库连接 -->
|
||||
<jdbcConnection driverClass="${jdbc.driver}"
|
||||
connectionURL="${jdbc.url}"
|
||||
userId="${jdbc.username}"
|
||||
password="${jdbc.password}" />
|
||||
|
||||
<!-- model生成 -->
|
||||
<javaModelGenerator targetPackage="${generator.javaModelGenerator.targetPackage}" targetProject="src/main/java" />
|
||||
<!-- model生成 -->
|
||||
<javaModelGenerator targetPackage="com.zheng.ucenter.dao.model" targetProject="src/main/java" />
|
||||
|
||||
<!-- MapperXML生成 -->
|
||||
<sqlMapGenerator targetPackage="${generator.sqlMapGenerator.targetPackage}" targetProject="src/main/java" />
|
||||
<!-- MapperXML生成 -->
|
||||
<sqlMapGenerator targetPackage="com.zheng.ucenter.dao.mapper" targetProject="src/main/java" />
|
||||
|
||||
<!-- Mapper接口生成 -->
|
||||
<javaClientGenerator targetPackage="${generator.javaClientGenerator.targetPackage}" targetProject="src/main/java" type="XMLMAPPER" />
|
||||
<!-- Mapper接口生成 -->
|
||||
<javaClientGenerator targetPackage="com.zheng.ucenter.dao.mapper" targetProject="src/main/java" type="XMLMAPPER" />
|
||||
|
||||
<!-- 需要映射的表 -->
|
||||
<table tableName="user" domainObjectName="User">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true" />
|
||||
</table>
|
||||
<table tableName="book" domainObjectName="Book">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true" />
|
||||
</table>
|
||||
</context>
|
||||
<!-- 需要映射的表 -->
|
||||
</context>
|
||||
</generatorConfiguration>
|
|
@ -4,6 +4,3 @@ jdbc.username=root
|
|||
jdbc.password=123456
|
||||
|
||||
classPathEntry=D:/mysql-connector-java-5.1.34.jar
|
||||
generator.javaModelGenerator.targetPackage=com.zheng.ucenter.dao.model
|
||||
generator.sqlMapGenerator.targetPackage=com.zheng.ucenter.dao.mapper
|
||||
generator.javaClientGenerator.targetPackage=com.zheng.ucenter.dao.mapper
|
Loading…
Reference in New Issue