zheng-upms的GeneratorConfig.xml自动生成

This commit is contained in:
shuzheng 2017-01-10 23:34:31 +08:00
parent 7d47f762f5
commit 873d9eae7a
12 changed files with 142 additions and 116 deletions

View File

@ -0,0 +1,27 @@
package com.zheng.upms.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 = "upms";
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);
}
}

View File

@ -107,20 +107,17 @@
</if>
</delete>
<insert id="insert" parameterType="com.zheng.upms.dao.model.UpmsOrganization" >
<selectKey resultType="java.lang.Integer" keyProperty="organizationId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_organization (system_id, name, description
)
values (#{systemId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}
)
insert into upms_organization (organization_id, system_id, name,
description)
values (#{organizationId,jdbcType=INTEGER}, #{systemId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.zheng.upms.dao.model.UpmsOrganization" >
<selectKey resultType="java.lang.Integer" keyProperty="organizationId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_organization
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="organizationId != null" >
organization_id,
</if>
<if test="systemId != null" >
system_id,
</if>
@ -132,6 +129,9 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="organizationId != null" >
#{organizationId,jdbcType=INTEGER},
</if>
<if test="systemId != null" >
#{systemId,jdbcType=INTEGER},
</if>
@ -201,5 +201,5 @@
description = #{description,jdbcType=VARCHAR}
where organization_id = #{organizationId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -105,23 +105,23 @@
</if>
</delete>
<insert id="insert" parameterType="com.zheng.upms.dao.model.UpmsPermission" >
<selectKey resultType="java.lang.Integer" keyProperty="permissionId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_permission (system_id)
values (#{systemId,jdbcType=INTEGER})
insert into upms_permission (permission_id, system_id)
values (#{permissionId,jdbcType=INTEGER}, #{systemId,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.zheng.upms.dao.model.UpmsPermission" >
<selectKey resultType="java.lang.Integer" keyProperty="permissionId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_permission
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="permissionId != null" >
permission_id,
</if>
<if test="systemId != null" >
system_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="permissionId != null" >
#{permissionId,jdbcType=INTEGER},
</if>
<if test="systemId != null" >
#{systemId,jdbcType=INTEGER},
</if>
@ -169,5 +169,5 @@
set system_id = #{systemId,jdbcType=INTEGER}
where permission_id = #{permissionId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -110,22 +110,19 @@
</if>
</delete>
<insert id="insert" parameterType="com.zheng.upms.dao.model.UpmsRole" >
<selectKey resultType="java.lang.Integer" keyProperty="roleId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_role (system_id, name, description,
status, ctime, orders
)
values (#{systemId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{status,jdbcType=TINYINT}, #{ctime,jdbcType=BIGINT}, #{orders,jdbcType=BIGINT}
)
insert into upms_role (role_id, system_id, name,
description, status, ctime,
orders)
values (#{roleId,jdbcType=INTEGER}, #{systemId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, #{ctime,jdbcType=BIGINT},
#{orders,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="com.zheng.upms.dao.model.UpmsRole" >
<selectKey resultType="java.lang.Integer" keyProperty="roleId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_role
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="roleId != null" >
role_id,
</if>
<if test="systemId != null" >
system_id,
</if>
@ -146,6 +143,9 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="roleId != null" >
#{roleId,jdbcType=INTEGER},
</if>
<if test="systemId != null" >
#{systemId,jdbcType=INTEGER},
</if>
@ -248,5 +248,5 @@
orders = #{orders,jdbcType=BIGINT}
where role_id = #{roleId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -186,5 +186,5 @@
permission_id = #{permissionId,jdbcType=INTEGER}
where role_permission_id = #{rolePermissionId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -110,20 +110,19 @@
</if>
</delete>
<insert id="insert" parameterType="com.zheng.upms.dao.model.UpmsSystem" >
<selectKey resultType="java.lang.Integer" keyProperty="systemId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_system (icon, basepath, status,
name, ctime, orders)
values (#{icon,jdbcType=VARCHAR}, #{basepath,jdbcType=VARCHAR}, #{status,jdbcType=SMALLINT},
#{name,jdbcType=VARCHAR}, #{ctime,jdbcType=BIGINT}, #{orders,jdbcType=BIGINT})
insert into upms_system (system_id, icon, basepath,
status, name, ctime,
orders)
values (#{systemId,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR}, #{basepath,jdbcType=VARCHAR},
#{status,jdbcType=SMALLINT}, #{name,jdbcType=VARCHAR}, #{ctime,jdbcType=BIGINT},
#{orders,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="com.zheng.upms.dao.model.UpmsSystem" >
<selectKey resultType="java.lang.Integer" keyProperty="systemId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_system
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="systemId != null" >
system_id,
</if>
<if test="icon != null" >
icon,
</if>
@ -144,6 +143,9 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="systemId != null" >
#{systemId,jdbcType=INTEGER},
</if>
<if test="icon != null" >
#{icon,jdbcType=VARCHAR},
</if>
@ -246,5 +248,5 @@
orders = #{orders,jdbcType=BIGINT}
where system_id = #{systemId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -105,23 +105,23 @@
</if>
</delete>
<insert id="insert" parameterType="com.zheng.upms.dao.model.UpmsUser" >
<selectKey resultType="java.lang.Integer" keyProperty="userId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_user (system_id)
values (#{systemId,jdbcType=INTEGER})
insert into upms_user (user_id, system_id)
values (#{userId,jdbcType=INTEGER}, #{systemId,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.zheng.upms.dao.model.UpmsUser" >
<selectKey resultType="java.lang.Integer" keyProperty="userId" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into upms_user
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="userId != null" >
user_id,
</if>
<if test="systemId != null" >
system_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="userId != null" >
#{userId,jdbcType=INTEGER},
</if>
<if test="systemId != null" >
#{systemId,jdbcType=INTEGER},
</if>
@ -169,5 +169,5 @@
set system_id = #{systemId,jdbcType=INTEGER}
where user_id = #{userId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -186,5 +186,5 @@
organization_id = #{organizationId,jdbcType=INTEGER}
where user_organization_id = #{userOrganizationId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -186,5 +186,5 @@
permission_id = #{permissionId,jdbcType=INTEGER}
where user_permission_id = #{userPermissionId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -201,5 +201,5 @@
role = #{role,jdbcType=INTEGER}
where user_role_id = #{userRoleId,jdbcType=INTEGER}
</update>
<cache />
<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />
</mapper>

View File

@ -2,76 +2,76 @@
<!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.upms.dao.model" targetProject="src/main/java" />
<!-- MapperXML生成 -->
<sqlMapGenerator targetPackage="${generator.sqlMapGenerator.targetPackage}" targetProject="src/main/java" />
<!-- MapperXML生成 -->
<sqlMapGenerator targetPackage="com.zheng.upms.dao.mapper" targetProject="src/main/java" />
<!-- Mapper接口生成 -->
<javaClientGenerator targetPackage="${generator.javaClientGenerator.targetPackage}" targetProject="src/main/java" type="XMLMAPPER" />
<!-- Mapper接口生成 -->
<javaClientGenerator targetPackage="com.zheng.upms.dao.mapper" targetProject="src/main/java" type="XMLMAPPER" />
<!-- 需要映射的表 -->
<table tableName="upms_system" domainObjectName="UpmsSystem">
<generatedKey column="system_id" sqlStatement="MySql" identity="true" />
</table>
<table tableName="upms_organization" domainObjectName="UpmsOrganization">
<generatedKey column="organization_id" sqlStatement="MySql" identity="true" />
</table>
<table tableName="upms_role" domainObjectName="UpmsRole">
<generatedKey column="role_id" sqlStatement="MySql" identity="true" />
</table>
<table tableName="upms_user" domainObjectName="UpmsUser">
<generatedKey column="user_id" sqlStatement="MySql" identity="true" />
</table>
<table tableName="upms_permission" domainObjectName="UpmsPermission">
<generatedKey column="permission_id" sqlStatement="MySql" identity="true" />
</table>
<table tableName="upms_user_organization" domainObjectName="UpmsUserOrganization"></table>
<table tableName="upms_user_role" domainObjectName="UpmsUserRole"></table>
<table tableName="upms_user_permission" domainObjectName="UpmsUserPermission"></table>
<table tableName="upms_role_permission" domainObjectName="UpmsRolePermission"></table>
</context>
<!-- 需要映射的表 -->
<table tableName="upms_organization" domainObjectName="UpmsOrganization"></table>
<table tableName="upms_permission" domainObjectName="UpmsPermission"></table>
<table tableName="upms_role" domainObjectName="UpmsRole"></table>
<table tableName="upms_role_permission" domainObjectName="UpmsRolePermission"></table>
<table tableName="upms_system" domainObjectName="UpmsSystem"></table>
<table tableName="upms_user" domainObjectName="UpmsUser"></table>
<table tableName="upms_user_organization" domainObjectName="UpmsUserOrganization"></table>
<table tableName="upms_user_permission" domainObjectName="UpmsUserPermission"></table>
<table tableName="upms_user_role" domainObjectName="UpmsUserRole"></table>
</context>
</generatorConfiguration>

View File

@ -3,7 +3,4 @@ jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/zheng?useUnicode\=true&characterEncoding
jdbc.username=root
jdbc.password=123456
classPathEntry=D:/mysql-connector-java-5.1.34.jar
generator.javaModelGenerator.targetPackage=com.zheng.upms.dao.model
generator.sqlMapGenerator.targetPackage=com.zheng.upms.dao.mapper
generator.javaClientGenerator.targetPackage=com.zheng.upms.dao.mapper
classPathEntry=D:/mysql-connector-java-5.1.34.jar