Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
120e4fc76b | ||
|
|
c5cae9903c | ||
|
|
3191da4c95 | ||
|
|
df7be169ba | ||
|
|
4d02bb9b50 | ||
|
|
4d24804f2c | ||
|
|
56a2399e8c | ||
|
|
a1735681d5 | ||
|
|
0e244ee3f8 | ||
|
|
ffcbdc12cb | ||
|
|
ccbdad7eba | ||
|
|
46793b3601 | ||
|
|
cc043ac38c | ||
|
|
c4b2769540 | ||
|
|
4aef323383 |
@@ -16,6 +16,7 @@
|
||||
* [Selective选择插入更新增强插件(SelectiveEnhancedPlugin)](#10-selective选择插入更新增强插件)
|
||||
* [Table增加前缀插件(TablePrefixPlugin)](#11-table增加前缀插件)
|
||||
* [Table重命名插件(TableRenamePlugin)](#12-table重命名插件)
|
||||
* [自定义注释插件(CommentPlugin)](#13-自定义注释插件)
|
||||
|
||||
---------------------------------------
|
||||
Maven引用:
|
||||
@@ -23,10 +24,40 @@ Maven引用:
|
||||
<dependency>
|
||||
<groupId>com.itfsw</groupId>
|
||||
<artifactId>mybatis-generator-plugin</artifactId>
|
||||
<version>1.0.10</version>
|
||||
<version>1.0.12</version>
|
||||
</dependency>
|
||||
```
|
||||
---------------------------------------
|
||||
MyBatis Generator 参考配置(插件依赖应该配置在mybatis-generator-maven-plugin插件依赖中[[issues#6]](https://github.com/itfsw/mybatis-generator-plugin/issues/6))
|
||||
```xml
|
||||
<!-- mybatis-generator 自动代码插件 -->
|
||||
<plugin>
|
||||
<groupId>org.mybatis.generator</groupId>
|
||||
<artifactId>mybatis-generator-maven-plugin</artifactId>
|
||||
<version>1.3.5</version>
|
||||
<configuration>
|
||||
<!-- 配置文件 -->
|
||||
<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
|
||||
<!-- 允许移动和修改 -->
|
||||
<verbose>true</verbose>
|
||||
<overwrite>true</overwrite>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<!-- jdbc 依赖 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.driver.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itfsw</groupId>
|
||||
<artifactId>mybatis-generator-plugin</artifactId>
|
||||
<version>${mybatis.generator.plugin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
```
|
||||
---------------------------------------
|
||||
### 1. 查询单条数据插件
|
||||
对应表Mapper接口增加了方法
|
||||
插件:
|
||||
@@ -504,7 +535,7 @@ public class Test {
|
||||
```
|
||||
### 10. Selective选择插入更新增强插件
|
||||
项目中往往需要指定某些字段进行插入或者更新,或者把某些字段进行设置null处理,这种情况下原生xxxSelective方法往往不能达到需求,因为它的判断条件是对象字段是否为null,这种情况下可使用该插件对xxxSelective方法进行增强。
|
||||
WAREN:配置插件时请把插件配置在所有插件末尾最后执行,这样才能把上面提供的某些插件的Selective方法也同时增强!
|
||||
>warning:配置插件时请把插件配置在所有插件末尾最后执行,这样才能把上面提供的某些插件的Selective方法也同时增强!
|
||||
|
||||
插件:
|
||||
```xml
|
||||
@@ -555,12 +586,12 @@ public class Test {
|
||||
### 11. Table增加前缀插件
|
||||
项目中有时会遇到配置多数据源对应多业务的情况,这种情况下可能会出现不同数据源出现重复表名,造成异常冲突。
|
||||
该插件允许为表增加前缀,改变最终生成的Model、Mapper、Example类名以及xml名。
|
||||
warning: 请原谅我蹩脚的英文水平,一直没发现插件名称错了,1.0.9版本错误命名为TableSuffixPlugin,属性为suffix请新版本用户对应修正!
|
||||
>warning: 请原谅我蹩脚的英文水平,一直没发现插件名称错了,1.0.9版本错误命名为TableSuffixPlugin,属性为suffix请新版本用户对应修正!
|
||||
|
||||
插件:
|
||||
```xml
|
||||
<!-- Table增加前缀插件 -->
|
||||
<xml>
|
||||
<!-- Table增加前缀插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TablePrefixPlugin">
|
||||
<!-- 这里配置的是全局表前缀,当然在table中配置的值会覆盖该全局配置 -->
|
||||
<property name="prefix" value="Cm"/>
|
||||
@@ -594,12 +625,12 @@ public class Test {
|
||||
这种情况下我们就希望能有类似[columnRenamingRule](http://www.mybatis.org/generator/configreference/columnRenamingRule.html)这种重命名插件来修正最终生成的Model、Mapper等命名。
|
||||
>该插件解决:使用正则替换table生成的Model、Example、Mapper等命名。
|
||||
|
||||
warning:和插件[Table增加前缀插件](#11-table增加前缀插件)联合使用时,需注意顺序问题。
|
||||
>warning:和插件[Table增加前缀插件](#11-table增加前缀插件)联合使用时,需注意顺序问题。
|
||||
|
||||
插件:
|
||||
```xml
|
||||
<!-- Table重命名插件 -->
|
||||
<xml>
|
||||
<!-- Table重命名插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.TablePrefixPlugin">
|
||||
<!-- 可根据具体需求确定是否配置 -->
|
||||
<property name="searchString" value="^T"/>
|
||||
@@ -631,4 +662,322 @@ public class Test {
|
||||
// xml文件名: TBookMapper.xml -> TestDbMapper.xml
|
||||
}
|
||||
}
|
||||
```
|
||||
### 13. 自定义注释插件
|
||||
Mybatis Generator是原生支持自定义注释的(commentGenerator配置type属性),但使用比较麻烦需要自己实现CommentGenerator接口并打包配置赖等等。
|
||||
该插件借助freemarker极佳的灵活性实现了自定义注释的快速配置。
|
||||
>warning: 下方提供了一个参考模板,需要注意${mgb}的输出,因为Mybatis Generator就是通过该字符串判断是否为自身生成代码进行覆盖重写。
|
||||
|
||||
>warning: 请注意拷贝参考模板注释前方空格,idea等工具拷贝进去后自动格式化会造成格式错乱。
|
||||
|
||||
>warning: 模板引擎采用的是freemarker所以一些freemarker指令参数(如:<#if xx></#if>、${.now?string("yyyy-MM-dd HH:mm:ss")})都是可以使用的,请自己尝试。
|
||||
|
||||
| 注释ID | 传入参数 | 备注 |
|
||||
| ----- | ----- | ---- |
|
||||
| addJavaFileComment | mgb<br>compilationUnit | Java文件注释 |
|
||||
| addComment | mgb<br>xmlElement | Xml节点注释 |
|
||||
| addRootComment | mgb<br>rootElement | Xml根节点注释 |
|
||||
| addFieldComment | mgb<br>field<br>introspectedTable<br>introspectedColumn | Java 字段注释(非生成Model对应表字段时,introspectedColumn可能不存在) |
|
||||
| addModelClassComment | mgb<br>topLevelClass<br>introspectedTable | 表Model类注释 |
|
||||
| addClassComment | mgb<br>innerClass<br>introspectedTable | 类注释 |
|
||||
| addEnumComment | mgb<br>innerEnum<br>introspectedTable | 枚举注释 |
|
||||
| addInterfaceComment | mgb<br>innerInterface<br>introspectedTable | 接口注释(itfsw插件新增类型) |
|
||||
| addGetterComment | mgb<br>method<br>introspectedTable<br>introspectedColumn | getter方法注释(introspectedColumn可能不存在) |
|
||||
| addSetterComment | mgb<br>method<br>introspectedTable<br>introspectedColumn | getter方法注释(introspectedColumn可能不存在) |
|
||||
| addGeneralMethodComment | mgb<br>method<br>introspectedTable | 方法注释 |
|
||||
|
||||
插件:
|
||||
```xml
|
||||
<xml>
|
||||
<!-- 自定义注释插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.CommentPlugin">
|
||||
<!-- 自定义模板路径 -->
|
||||
<property name="template" value="src/main/resources/mybatis-generator-comment.ftl" />
|
||||
</plugin>
|
||||
</xml>
|
||||
```
|
||||
使用(参考模板):
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method is called to add a file level comment to a generated java file. This method could be used to add a
|
||||
* general file comment (such as a copyright notice). However, note that the Java file merge function in Eclipse
|
||||
* does not deal with this comment. If you run the generator repeatedly, you will only retain the comment from the
|
||||
* initial run.
|
||||
* <p>
|
||||
*
|
||||
* The default implementation does nothing.
|
||||
*
|
||||
* @param compilationUnit
|
||||
* the compilation unit
|
||||
*/
|
||||
-->
|
||||
<comment ID="addJavaFileComment"></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method should add a suitable comment as a child element of the specified xmlElement to warn users that the
|
||||
* element was generated and is subject to regeneration.
|
||||
*
|
||||
* @param xmlElement
|
||||
* the xml element
|
||||
*/
|
||||
-->
|
||||
<comment ID="addComment"><![CDATA[
|
||||
<!--
|
||||
WARNING - ${mgb}
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
@project https://github.com/itfsw/mybatis-generator-plugin
|
||||
-->
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method is called to add a comment as the first child of the root element. This method could be used to add a
|
||||
* general file comment (such as a copyright notice). However, note that the XML file merge function does not deal
|
||||
* with this comment. If you run the generator repeatedly, you will only retain the comment from the initial run.
|
||||
* <p>
|
||||
*
|
||||
* The default implementation does nothing.
|
||||
*
|
||||
* @param rootElement
|
||||
* the root element
|
||||
*/
|
||||
-->
|
||||
<comment ID="addRootComment"></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method should add a Javadoc comment to the specified field. The field is related to the specified table and
|
||||
* is used to hold the value of the specified column.
|
||||
* <p>
|
||||
*
|
||||
* <b>Important:</b> This method should add a the nonstandard JavaDoc tag "@mbg.generated" to the comment. Without
|
||||
* this tag, the Eclipse based Java merge feature will fail.
|
||||
*
|
||||
* @param field
|
||||
* the field
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
-->
|
||||
<comment ID="addFieldComment"><![CDATA[
|
||||
<#if introspectedColumn??>
|
||||
/**
|
||||
<#if introspectedColumn.remarks?? && introspectedColumn.remarks != ''>
|
||||
* Database Column Remarks:
|
||||
<#list introspectedColumn.remarks?split("\n") as remark>
|
||||
* ${remark}
|
||||
</#list>
|
||||
</#if>
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
<#else>
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
</#if>
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds a comment for a model class. The Java code merger should
|
||||
* be notified not to delete the entire class in case any manual
|
||||
* changes have been made. So this method will always use the
|
||||
* "do not delete" annotation.
|
||||
*
|
||||
* Because of difficulties with the Java file merger, the default implementation
|
||||
* of this method should NOT add comments. Comments should only be added if
|
||||
* specifically requested by the user (for example, by enabling table remark comments).
|
||||
*
|
||||
* @param topLevelClass
|
||||
* the top level class
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addModelClassComment"><![CDATA[
|
||||
/**
|
||||
<#if introspectedTable.remarks?? && introspectedTable.remarks != ''>
|
||||
* Database Table Remarks:
|
||||
<#list introspectedTable.remarks?split("\n") as remark>
|
||||
* ${remark}
|
||||
</#list>
|
||||
</#if>
|
||||
*
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb} do_not_delete_during_merge
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the inner class comment.
|
||||
*
|
||||
* @param innerClass
|
||||
* the inner class
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param markAsDoNotDelete
|
||||
* the mark as do not delete
|
||||
*/
|
||||
-->
|
||||
<comment ID="addClassComment"><![CDATA[
|
||||
/**
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}<#if markAsDoNotDelete?? && markAsDoNotDelete> do_not_delete_during_merge</#if>
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the enum comment.
|
||||
*
|
||||
* @param innerEnum
|
||||
* the inner enum
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addEnumComment"><![CDATA[
|
||||
/**
|
||||
* This enum was generated by MyBatis Generator.
|
||||
* This enum corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the interface comment.
|
||||
*
|
||||
* @param innerInterface
|
||||
* the inner interface
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addInterfaceComment"><![CDATA[
|
||||
/**
|
||||
* This interface was generated by MyBatis Generator.
|
||||
* This interface corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the getter comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
-->
|
||||
<comment ID="addGetterComment"><![CDATA[
|
||||
<#if introspectedColumn??>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* @return the value of ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
<#else>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the field ${method.name?replace("get","")?replace("is", "")?uncap_first}
|
||||
*
|
||||
* @return the value of field ${method.name?replace("get","")?replace("is", "")?uncap_first}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
</#if>
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the setter comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
-->
|
||||
<comment ID="addSetterComment"><![CDATA[
|
||||
<#if introspectedColumn??>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* @param ${method.parameters[0].name} the value for ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
<#else>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the field ${method.name?replace("set","")?uncap_first}
|
||||
*
|
||||
* @param ${method.parameters[0].name} the value for field ${method.name?replace("set","")?uncap_first}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
</#if>
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the general method comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addGeneralMethodComment"><![CDATA[
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
</template>
|
||||
```
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<groupId>com.itfsw</groupId>
|
||||
<artifactId>mybatis-generator-plugin</artifactId>
|
||||
<version>1.0.10</version>
|
||||
<version>1.0.12</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.groupId}:${project.artifactId}</name>
|
||||
@@ -41,6 +41,18 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.22</version>
|
||||
</dependency>
|
||||
<!-- 模板引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.26-incubating</version>
|
||||
</dependency>
|
||||
<!-- xml 解析 -->
|
||||
<dependency>
|
||||
<groupId>dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<!-- junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@@ -175,7 +187,7 @@
|
||||
<connection>scm:git:https://github.com/itfsw/mybatis-generator-plugin.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/itfsw/mybatis-generator-plugin.git</developerConnection>
|
||||
<url>https://github.com/itfsw/mybatis-generator-plugin</url>
|
||||
<tag>V1.0.10</tag>
|
||||
<tag>V1.0.12</tag>
|
||||
</scm>
|
||||
|
||||
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++distribution++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2017.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.utils.BasePlugin;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
* 评论插件
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2017/6/8 11:21
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class CommentPlugin extends BasePlugin {
|
||||
public static final String PRE_TEMPLATE = "template"; // 模板 property
|
||||
|
||||
/**
|
||||
* 插件具体实现查看BasePlugin
|
||||
* @param properties
|
||||
*/
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
super.setProperties(properties);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,6 @@ public class ExampleEnhancedPlugin extends BasePlugin {
|
||||
// 添加接口CriteriaAdd
|
||||
InnerInterface criteriaAddInterface = new InnerInterface("ICriteriaAdd");
|
||||
criteriaAddInterface.setVisibility(JavaVisibility.PUBLIC);
|
||||
commentGenerator.addInterfaceComment(criteriaAddInterface, introspectedTable);
|
||||
logger.debug("itfsw(Example增强插件):" + topLevelClass.getType().getShortName() + "." + innerClass.getType().getShortName() + "增加接口ICriteriaAdd");
|
||||
|
||||
// ICriteriaAdd增加接口add
|
||||
@@ -121,6 +120,8 @@ public class ExampleEnhancedPlugin extends BasePlugin {
|
||||
logger.debug("itfsw(Example增强插件):" + topLevelClass.getType().getShortName() + "." + innerClass.getType().getShortName() + "." + criteriaAddInterface.getType().getShortName() + "增加方法add");
|
||||
|
||||
InnerClass innerClassWrapper = new InnerInterfaceWrapperToInnerClass(criteriaAddInterface);
|
||||
// 添加注释
|
||||
commentGenerator.addClassComment(innerClassWrapper, introspectedTable);
|
||||
innerClass.addInnerClass(innerClassWrapper);
|
||||
|
||||
// 添加andIf方法
|
||||
|
||||
@@ -232,37 +232,42 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
|
||||
XmlElement whenEle = new XmlElement("when");
|
||||
whenEle.addAttribute(new Attribute("test", prefix + "isSelective()"));
|
||||
for (Element ele : element.getElements()) {
|
||||
// if的text节点
|
||||
XmlElement xmlElement = (XmlElement) ele;
|
||||
TextElement textElement = (TextElement) xmlElement.getElements().get(0);
|
||||
// 对于字符串主键,是没有if判断节点的
|
||||
if (ele instanceof XmlElement){
|
||||
// if的text节点
|
||||
XmlElement xmlElement = (XmlElement) ele;
|
||||
TextElement textElement = (TextElement) xmlElement.getElements().get(0);
|
||||
|
||||
// 找出field 名称
|
||||
String text = textElement.getContent().trim();
|
||||
String field = "";
|
||||
if (text.matches(".*\\s*=\\s*#\\{.*\\},?")) {
|
||||
Pattern pattern = Pattern.compile("(.*?)\\s*=\\s*#\\{.*},?");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
if (matcher.find()){
|
||||
field = matcher.group(1);
|
||||
}
|
||||
} else if (text.matches("#\\{.*\\},?")) {
|
||||
Pattern pattern = Pattern.compile("#\\{(.*?),.*\\},?");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
if (matcher.find()){
|
||||
field = matcher.group(1);
|
||||
// 找出field 名称
|
||||
String text = textElement.getContent().trim();
|
||||
String field = "";
|
||||
if (text.matches(".*\\s*=\\s*#\\{.*\\},?")) {
|
||||
Pattern pattern = Pattern.compile("(.*?)\\s*=\\s*#\\{.*},?");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
if (matcher.find()){
|
||||
field = matcher.group(1);
|
||||
}
|
||||
} else if (text.matches("#\\{.*\\},?")) {
|
||||
Pattern pattern = Pattern.compile("#\\{(.*?),.*\\},?");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
if (matcher.find()){
|
||||
field = matcher.group(1);
|
||||
}
|
||||
} else {
|
||||
field = text.replaceAll(",", "");
|
||||
}
|
||||
|
||||
XmlElement ifEle = new XmlElement("if");
|
||||
|
||||
// bug fixed: 修正使用autoDelimitKeywords过滤关键词造成的field前后加了特殊字符的问题
|
||||
field = field.replaceAll("`", "").replaceAll("\"", "").replaceAll("'", "");
|
||||
|
||||
ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + field + "\')"));
|
||||
ifEle.addElement(textElement);
|
||||
whenEle.addElement(ifEle);
|
||||
} else {
|
||||
field = text.replaceAll(",", "");
|
||||
whenEle.addElement(ele);
|
||||
}
|
||||
|
||||
XmlElement ifEle = new XmlElement("if");
|
||||
|
||||
// bug fixed: 修正使用autoDelimitKeywords过滤关键词造成的field前后加了特殊字符的问题
|
||||
field = field.replaceAll("`", "").replaceAll("\"", "").replaceAll("'", "");
|
||||
|
||||
ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + field + "\')"));
|
||||
ifEle.addElement(textElement);
|
||||
whenEle.addElement(ifEle);
|
||||
}
|
||||
|
||||
// otherwise
|
||||
|
||||
@@ -17,7 +17,11 @@
|
||||
package com.itfsw.mybatis.generator.plugins;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.utils.BasePlugin;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.IntrospectedTableTools;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.config.TableConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
@@ -32,10 +36,26 @@ public class TablePrefixPlugin extends BasePlugin {
|
||||
public static final String PRE_PREFIX = "prefix"; // 前缀 property
|
||||
private String prefix; // 前缀
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean validate(List<String> warnings) {
|
||||
// 如果table配置了domainObjectName或者mapperName就不要再启动该插件了
|
||||
for (TableConfiguration tableConfiguration : context.getTableConfigurations()) {
|
||||
if (tableConfiguration.getDomainObjectName() != null || tableConfiguration.getMapperName() != null) {
|
||||
logger.warn("itfsw:插件" + this.getClass().getTypeName() + "插件请不要配合table的domainObjectName或者mapperName一起使用!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return super.validate(warnings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化阶段
|
||||
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
|
||||
*
|
||||
* @param introspectedTable
|
||||
* @return
|
||||
*/
|
||||
@@ -44,61 +64,19 @@ public class TablePrefixPlugin extends BasePlugin {
|
||||
// 1. 首先获取全局配置
|
||||
this.prefix = getProperties().getProperty(PRE_PREFIX);
|
||||
// 2. 获取每个table 具体的
|
||||
if (introspectedTable.getTableConfigurationProperty(PRE_PREFIX) != null){
|
||||
if (introspectedTable.getTableConfigurationProperty(PRE_PREFIX) != null) {
|
||||
this.prefix = introspectedTable.getTableConfigurationProperty(PRE_PREFIX);
|
||||
}
|
||||
// 3. 判断是否配置了前缀
|
||||
if (this.prefix != null){
|
||||
// 3.1. 为Model增加前缀
|
||||
if (introspectedTable.getBaseRecordType() != null){
|
||||
introspectedTable.setBaseRecordType(this.renameJavaType(introspectedTable.getBaseRecordType()));
|
||||
}
|
||||
|
||||
// 3.2. 为ModelKey添加前缀
|
||||
if (introspectedTable.getPrimaryKeyType() != null){
|
||||
introspectedTable.setPrimaryKeyType(this.renameJavaType(introspectedTable.getPrimaryKeyType()));
|
||||
}
|
||||
|
||||
// 3.3. WithBLOBs Model 添加前缀
|
||||
if (introspectedTable.getRecordWithBLOBsType() != null){
|
||||
introspectedTable.setRecordWithBLOBsType(this.renameJavaType(introspectedTable.getRecordWithBLOBsType()));
|
||||
}
|
||||
|
||||
// 3.4. mapper 添加前缀
|
||||
if (introspectedTable.getMyBatis3JavaMapperType() != null){
|
||||
introspectedTable.setMyBatis3JavaMapperType(this.renameJavaType(introspectedTable.getMyBatis3JavaMapperType()));
|
||||
}
|
||||
|
||||
// 3.5. example 添加前缀
|
||||
if (introspectedTable.getExampleType() != null){
|
||||
introspectedTable.setExampleType(this.renameJavaType(introspectedTable.getExampleType()));
|
||||
}
|
||||
|
||||
// 3.6. Dao 添加前缀
|
||||
if (introspectedTable.getDAOInterfaceType() != null){
|
||||
introspectedTable.setDAOInterfaceType(this.renameJavaType(introspectedTable.getDAOInterfaceType()));
|
||||
}
|
||||
|
||||
// 3.7. DAOImpl 添加前缀
|
||||
if (introspectedTable.getDAOImplementationType() != null){
|
||||
introspectedTable.setDAOImplementationType(this.renameJavaType(introspectedTable.getDAOImplementationType()));
|
||||
}
|
||||
|
||||
// 3.8. 修正xml文件前缀
|
||||
if (introspectedTable.getMyBatis3XmlMapperFileName() != null){
|
||||
introspectedTable.setMyBatis3XmlMapperFileName(this.prefix + introspectedTable.getMyBatis3XmlMapperFileName());
|
||||
// !!! TableRenamePlugin 插件的 tableOverride 优先级最高
|
||||
if (this.prefix != null && introspectedTable.getTableConfigurationProperty(TableRenamePlugin.PRE_TABLE_OVERRIDE) == null) {
|
||||
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
|
||||
domainObjectName = prefix + domainObjectName;
|
||||
try {
|
||||
IntrospectedTableTools.setDomainObjectName(introspectedTable, getContext(), domainObjectName);
|
||||
} catch (Exception e) {
|
||||
logger.error("itfsw:插件" + this.getClass().getTypeName() + "使用prefix替换时异常!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为类型添加前缀
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private String renameJavaType(String type){
|
||||
int lastDot = type.lastIndexOf(".") + 1;
|
||||
return type.substring(0, lastDot) + this.prefix + type.substring(lastDot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
package com.itfsw.mybatis.generator.plugins;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.utils.BasePlugin;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.IntrospectedTableTools;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.config.TableConfiguration;
|
||||
import org.mybatis.generator.internal.util.JavaBeansUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -49,6 +52,14 @@ public class TableRenamePlugin extends BasePlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果table配置了domainObjectName或者mapperName就不要再启动该插件了
|
||||
for (TableConfiguration tableConfiguration: context.getTableConfigurations()) {
|
||||
if (tableConfiguration.getDomainObjectName() != null || tableConfiguration.getMapperName() != null){
|
||||
logger.warn("itfsw:插件" + this.getClass().getTypeName() + "插件请不要配合table的domainObjectName或者mapperName一起使用!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return super.validate(warnings);
|
||||
}
|
||||
|
||||
@@ -63,126 +74,26 @@ public class TableRenamePlugin extends BasePlugin {
|
||||
// 1. 获取表单独配置
|
||||
if (introspectedTable.getTableConfigurationProperty(PRE_TABLE_OVERRIDE) != null) {
|
||||
String override = introspectedTable.getTableConfigurationProperty(PRE_TABLE_OVERRIDE);
|
||||
|
||||
// 3.1. Model修正名称
|
||||
if (introspectedTable.getBaseRecordType() != null){
|
||||
introspectedTable.setBaseRecordType(this.renameJavaType(introspectedTable.getBaseRecordType(), override, ""));
|
||||
}
|
||||
|
||||
// 3.2. ModelKey修正名称
|
||||
if (introspectedTable.getPrimaryKeyType() != null){
|
||||
introspectedTable.setPrimaryKeyType(this.renameJavaType(introspectedTable.getPrimaryKeyType(), override, "Key"));
|
||||
}
|
||||
|
||||
// 3.3. WithBLOBs Model 修正名称
|
||||
if (introspectedTable.getRecordWithBLOBsType() != null){
|
||||
introspectedTable.setRecordWithBLOBsType(this.renameJavaType(introspectedTable.getRecordWithBLOBsType(), override, "WithBLOBs"));
|
||||
}
|
||||
|
||||
// 3.4. mapper 修正名称
|
||||
if (introspectedTable.getMyBatis3JavaMapperType() != null){
|
||||
introspectedTable.setMyBatis3JavaMapperType(this.renameJavaType(introspectedTable.getMyBatis3JavaMapperType(), override, "Mapper"));
|
||||
}
|
||||
|
||||
// 3.5. example 修正名称
|
||||
if (introspectedTable.getExampleType() != null){
|
||||
introspectedTable.setExampleType(this.renameJavaType(introspectedTable.getExampleType(), override, "Example"));
|
||||
}
|
||||
|
||||
// 3.6. Dao 添加前缀
|
||||
if (introspectedTable.getDAOInterfaceType() != null){
|
||||
introspectedTable.setDAOInterfaceType(this.renameJavaType(introspectedTable.getDAOInterfaceType(), override, "Dao"));
|
||||
}
|
||||
|
||||
// 3.7. DAOImpl 添加前缀
|
||||
if (introspectedTable.getDAOImplementationType() != null){
|
||||
introspectedTable.setDAOImplementationType(this.renameJavaType(introspectedTable.getDAOImplementationType(), override, "DAOImpl"));
|
||||
}
|
||||
|
||||
// 3.8. 修正xml文件名称
|
||||
if (introspectedTable.getMyBatis3XmlMapperFileName() != null){
|
||||
introspectedTable.setMyBatis3XmlMapperFileName(override + "Mapper.xml");
|
||||
try {
|
||||
IntrospectedTableTools.setDomainObjectName(introspectedTable, getContext(), override);
|
||||
} catch (Exception e) {
|
||||
logger.error("itfsw:插件" + this.getClass().getTypeName() + "使用tableOverride替换时异常!", e);
|
||||
}
|
||||
} else if (getProperties().getProperty(PRE_SEARCH_STRING) != null){
|
||||
String searchString = getProperties().getProperty(PRE_SEARCH_STRING);
|
||||
String replaceString = getProperties().getProperty(PRE_REPLACE_STRING);
|
||||
|
||||
// 3.1. Model修正名称
|
||||
if (introspectedTable.getBaseRecordType() != null){
|
||||
introspectedTable.setBaseRecordType(this.renameJavaType(introspectedTable.getBaseRecordType(), searchString, replaceString, ""));
|
||||
}
|
||||
|
||||
// 3.2. ModelKey修正名称
|
||||
if (introspectedTable.getPrimaryKeyType() != null){
|
||||
introspectedTable.setPrimaryKeyType(this.renameJavaType(introspectedTable.getPrimaryKeyType(), searchString, replaceString, "Key"));
|
||||
}
|
||||
|
||||
// 3.3. WithBLOBs Model 修正名称
|
||||
if (introspectedTable.getRecordWithBLOBsType() != null){
|
||||
introspectedTable.setRecordWithBLOBsType(this.renameJavaType(introspectedTable.getRecordWithBLOBsType(), searchString, replaceString, "WithBLOBs"));
|
||||
}
|
||||
|
||||
// 3.4. mapper 修正名称
|
||||
if (introspectedTable.getMyBatis3JavaMapperType() != null){
|
||||
introspectedTable.setMyBatis3JavaMapperType(this.renameJavaType(introspectedTable.getMyBatis3JavaMapperType(), searchString, replaceString, "Mapper"));
|
||||
}
|
||||
|
||||
// 3.5. example 修正名称
|
||||
if (introspectedTable.getExampleType() != null){
|
||||
introspectedTable.setExampleType(this.renameJavaType(introspectedTable.getExampleType(), searchString, replaceString, "Example"));
|
||||
}
|
||||
|
||||
// 3.6. Dao 添加前缀
|
||||
if (introspectedTable.getDAOInterfaceType() != null){
|
||||
introspectedTable.setDAOInterfaceType(this.renameJavaType(introspectedTable.getDAOInterfaceType(), searchString, replaceString, "Dao"));
|
||||
}
|
||||
|
||||
// 3.7. DAOImpl 添加前缀
|
||||
if (introspectedTable.getDAOImplementationType() != null){
|
||||
introspectedTable.setDAOImplementationType(this.renameJavaType(introspectedTable.getDAOImplementationType(), searchString, replaceString, "DAOImpl"));
|
||||
}
|
||||
|
||||
// 3.8. 修正xml文件名称
|
||||
if (introspectedTable.getMyBatis3XmlMapperFileName() != null){
|
||||
Pattern pattern = Pattern.compile(searchString);
|
||||
Matcher matcher = pattern.matcher(introspectedTable.getMyBatis3XmlMapperFileName());
|
||||
String fileName = matcher.replaceAll(replaceString);
|
||||
introspectedTable.setMyBatis3XmlMapperFileName(fileName);
|
||||
String domainObjectName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
|
||||
Pattern pattern = Pattern.compile(searchString);
|
||||
Matcher matcher = pattern.matcher(domainObjectName);
|
||||
domainObjectName = matcher.replaceAll(replaceString);
|
||||
// 命名规范化
|
||||
domainObjectName = JavaBeansUtil.getCamelCaseString(domainObjectName, true);
|
||||
try {
|
||||
IntrospectedTableTools.setDomainObjectName(introspectedTable, getContext(), domainObjectName);
|
||||
} catch (Exception e) {
|
||||
logger.error("itfsw:插件" + this.getClass().getTypeName() + "使用searchString、replaceString替换时异常!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名类型
|
||||
*
|
||||
* @param type
|
||||
* @param override
|
||||
* @return
|
||||
*/
|
||||
private String renameJavaType(String type, String override, String suffix) {
|
||||
int lastDot = type.lastIndexOf(".");
|
||||
return type.substring(0, lastDot) + "." + override + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名类型
|
||||
*
|
||||
* @param type
|
||||
* @param searchString
|
||||
* @param replaceString
|
||||
* @return
|
||||
*/
|
||||
private String renameJavaType(String type, String searchString, String replaceString, String suffix) {
|
||||
int lastDot = type.lastIndexOf(".");
|
||||
String shortName = type.substring(lastDot + 1, type.length() - 1);
|
||||
|
||||
|
||||
Pattern pattern = Pattern.compile(searchString);
|
||||
Matcher matcher = pattern.matcher(shortName);
|
||||
logger.warn("===============================================================");
|
||||
logger.warn(shortName);
|
||||
logger.warn(type.substring(0, lastDot) + "." + matcher.replaceAll(replaceString) + suffix);
|
||||
|
||||
return type.substring(0, lastDot) + "." + matcher.replaceAll(replaceString) + suffix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,18 @@
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins.utils;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.utils.enhanced.IWCommentGenerator;
|
||||
import com.itfsw.mybatis.generator.plugins.CommentPlugin;
|
||||
import com.itfsw.mybatis.generator.plugins.utils.enhanced.TemplateCommentGenerator;
|
||||
import org.mybatis.generator.api.CommentGenerator;
|
||||
import org.mybatis.generator.api.PluginAdapter;
|
||||
import org.mybatis.generator.config.Context;
|
||||
import org.mybatis.generator.config.PluginConfiguration;
|
||||
import org.mybatis.generator.internal.DefaultCommentGenerator;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -34,7 +40,48 @@ import java.util.List;
|
||||
*/
|
||||
public class BasePlugin extends PluginAdapter {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(BasePlugin.class); // 日志
|
||||
protected IWCommentGenerator commentGenerator = new IWCommentGenerator(); // 注释工具
|
||||
protected CommentGenerator commentGenerator; // 注释工具
|
||||
|
||||
/**
|
||||
* Set the context under which this plugin is running.
|
||||
*
|
||||
* @param context
|
||||
* the new context
|
||||
*/
|
||||
@Override
|
||||
public void setContext(Context context) {
|
||||
super.setContext(context);
|
||||
|
||||
// 配置插件使用的模板引擎
|
||||
PluginConfiguration cfg = PluginTools.getPluginConfiguration(CommentPlugin.class, context);
|
||||
|
||||
if (cfg == null || cfg.getProperty(CommentPlugin.PRE_TEMPLATE) == null){
|
||||
if (context.getCommentGenerator() instanceof DefaultCommentGenerator){
|
||||
// 使用默认模板引擎
|
||||
commentGenerator = new TemplateCommentGenerator("default-comment.ftl", true);
|
||||
} else {
|
||||
// 用户自定义
|
||||
commentGenerator = context.getCommentGenerator();
|
||||
}
|
||||
} else {
|
||||
TemplateCommentGenerator templateCommentGenerator = new TemplateCommentGenerator(cfg.getProperty(CommentPlugin.PRE_TEMPLATE), false);
|
||||
|
||||
// ITFSW 插件使用的注释生成器
|
||||
commentGenerator = templateCommentGenerator;
|
||||
|
||||
// 修正系统插件
|
||||
try {
|
||||
// 先执行一次生成CommentGenerator操作,然后再替换
|
||||
context.getCommentGenerator();
|
||||
|
||||
Field field = Context.class.getDeclaredField("commentGenerator");
|
||||
field.setAccessible(true);
|
||||
field.set(context, templateCommentGenerator);
|
||||
} catch (Exception e) {
|
||||
logger.error("反射异常",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2017.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins.utils;
|
||||
|
||||
import com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin;
|
||||
import org.mybatis.generator.api.FullyQualifiedTable;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.config.Context;
|
||||
import org.mybatis.generator.config.JavaModelGeneratorConfiguration;
|
||||
import org.mybatis.generator.config.PluginConfiguration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
* IntrospectedTable 的一些拓展增强
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2017/6/13 13:48
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class IntrospectedTableTools {
|
||||
|
||||
/**
|
||||
* 设置DomainObjectName和MapperName
|
||||
*
|
||||
* @param introspectedTable
|
||||
* @param context
|
||||
* @param domainObjectName
|
||||
*/
|
||||
public static void setDomainObjectName(IntrospectedTable introspectedTable, Context context, String domainObjectName) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
||||
// 配置信息(没啥用)
|
||||
introspectedTable.getTableConfiguration().setDomainObjectName(domainObjectName);
|
||||
|
||||
// FullyQualifiedTable修正
|
||||
Field domainObjectNameField = FullyQualifiedTable.class.getDeclaredField("domainObjectName");
|
||||
domainObjectNameField.setAccessible(true);
|
||||
domainObjectNameField.set(introspectedTable.getFullyQualifiedTable(), domainObjectName);
|
||||
|
||||
// 重新修正introspectedTable属性信息
|
||||
Method calculateJavaClientAttributes = IntrospectedTable.class.getDeclaredMethod("calculateJavaClientAttributes");
|
||||
calculateJavaClientAttributes.setAccessible(true);
|
||||
calculateJavaClientAttributes.invoke(introspectedTable);
|
||||
|
||||
Method calculateModelAttributes = IntrospectedTable.class.getDeclaredMethod("calculateModelAttributes");
|
||||
calculateModelAttributes.setAccessible(true);
|
||||
calculateModelAttributes.invoke(introspectedTable);
|
||||
|
||||
Method calculateXmlAttributes = IntrospectedTable.class.getDeclaredMethod("calculateXmlAttributes");
|
||||
calculateXmlAttributes.setAccessible(true);
|
||||
calculateXmlAttributes.invoke(introspectedTable);
|
||||
|
||||
// 注意!! 如果配置了ExampleTargetPlugin插件,要修正Example 位置
|
||||
PluginConfiguration configuration = PluginTools.getPluginConfiguration(ExampleTargetPlugin.class, context);
|
||||
if (configuration != null && configuration.getProperty(ExampleTargetPlugin.TARGET_PACKAGE_KEY) != null){
|
||||
String exampleType = introspectedTable.getExampleType();
|
||||
// 修改包名
|
||||
JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = context.getJavaModelGeneratorConfiguration();
|
||||
String targetPackage = javaModelGeneratorConfiguration.getTargetPackage();
|
||||
String newExampleType = exampleType.replace(targetPackage, configuration.getProperty(ExampleTargetPlugin.TARGET_PACKAGE_KEY));
|
||||
|
||||
introspectedTable.setExampleType(newExampleType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,4 +81,19 @@ public class PluginTools {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件配置
|
||||
*
|
||||
* @param plugin 插件
|
||||
* @param ctx 上下文
|
||||
* @return
|
||||
*/
|
||||
public static PluginConfiguration getPluginConfiguration(Class plugin, Context ctx){
|
||||
int index = getPluginIndex(plugin, ctx);
|
||||
if (index > -1){
|
||||
return getConfigPlugins(ctx).get(index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
-335
@@ -1,335 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins.utils.enhanced;
|
||||
|
||||
import org.mybatis.generator.api.CommentGenerator;
|
||||
import org.mybatis.generator.api.IntrospectedColumn;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.dom.java.*;
|
||||
import org.mybatis.generator.api.dom.xml.TextElement;
|
||||
import org.mybatis.generator.api.dom.xml.XmlElement;
|
||||
import org.mybatis.generator.config.MergeConstants;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
* 注释生成工具
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2017/4/28 15:11
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class IWCommentGenerator implements CommentGenerator {
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addJavaFileComment(org.mybatis.generator.api.dom.java.CompilationUnit)
|
||||
*/
|
||||
public void addJavaFileComment(CompilationUnit compilationUnit) {
|
||||
// add no file level comments by default
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a suitable comment to warn users that the element was generated, and when it was generated.
|
||||
* @param xmlElement the xml element
|
||||
*/
|
||||
public void addComment(XmlElement xmlElement) {
|
||||
|
||||
xmlElement.addElement(new TextElement("<!--"));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" WARNING - ");
|
||||
sb.append(MergeConstants.NEW_ELEMENT_TAG);
|
||||
xmlElement.addElement(new TextElement(sb.toString()));
|
||||
xmlElement.addElement(new TextElement(" This element is automatically generated by MyBatis Generator, do not modify."));
|
||||
xmlElement.addElement(new TextElement(" @project https://github.com/itfsw/mybatis-generator-plugin"));
|
||||
xmlElement.addElement(new TextElement("-->"));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addRootComment(org.mybatis.generator.api.dom.xml.XmlElement)
|
||||
*/
|
||||
public void addRootComment(XmlElement rootElement) {
|
||||
// add no document level comments by default
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addConfigurationProperties(java.util.Properties)
|
||||
*/
|
||||
public void addConfigurationProperties(Properties properties) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds the custom javadoc tag for. You may do nothing if you do not wish to include the Javadoc tag -
|
||||
* however, if you do not include the Javadoc tag then the Java merge capability of the eclipse plugin will break.
|
||||
* @param javaElement the java element
|
||||
* @param markAsDoNotDelete the mark as do not delete
|
||||
*/
|
||||
protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
|
||||
javaElement.addJavaDocLine(" *");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" * ");
|
||||
sb.append(MergeConstants.NEW_ELEMENT_TAG);
|
||||
if (markAsDoNotDelete) {
|
||||
sb.append(" do_not_delete_during_merge");
|
||||
}
|
||||
|
||||
javaElement.addJavaDocLine(sb.toString());
|
||||
javaElement.addJavaDocLine(" * @project https://github.com/itfsw/mybatis-generator-plugin");
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addClassComment(org.mybatis.generator.api.dom.java.InnerClass, org.mybatis.generator.api.IntrospectedTable)
|
||||
*/
|
||||
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
innerClass.addJavaDocLine("/**");
|
||||
innerClass.addJavaDocLine(" * This class was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This class corresponds to the database table ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
innerClass.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(innerClass, false);
|
||||
|
||||
innerClass.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/**
|
||||
* inner inter face 注释
|
||||
*
|
||||
* @param innerInterface
|
||||
* @param introspectedTable
|
||||
*/
|
||||
public void addInterfaceComment(Interface innerInterface, IntrospectedTable introspectedTable) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
innerInterface.addJavaDocLine("/**");
|
||||
innerInterface.addJavaDocLine(" * This interface was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This interface corresponds to the database table ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
innerInterface.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(innerInterface, false);
|
||||
|
||||
innerInterface.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addTopLevelClassComment(org.mybatis.generator.api.dom.java.TopLevelClass, org.mybatis.generator.api.IntrospectedTable)
|
||||
*/
|
||||
@Override
|
||||
public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
topLevelClass.addJavaDocLine("/**");
|
||||
|
||||
String remarks = introspectedTable.getRemarks();
|
||||
if (StringUtility.stringHasValue(remarks)) {
|
||||
topLevelClass.addJavaDocLine(" * Database Table Remarks:");
|
||||
String[] remarkLines = remarks.split(System.getProperty("line.separator"));
|
||||
for (String remarkLine : remarkLines) {
|
||||
topLevelClass.addJavaDocLine(" * " + remarkLine);
|
||||
}
|
||||
}
|
||||
topLevelClass.addJavaDocLine(" *");
|
||||
|
||||
topLevelClass.addJavaDocLine(" * This class was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This class corresponds to the database table ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
topLevelClass.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(topLevelClass, true);
|
||||
|
||||
topLevelClass.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addEnumComment(org.mybatis.generator.api.dom.java.InnerEnum, org.mybatis.generator.api.IntrospectedTable)
|
||||
*/
|
||||
public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
innerEnum.addJavaDocLine("/**");
|
||||
innerEnum.addJavaDocLine(" * This enum was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This enum corresponds to the database table ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
innerEnum.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(innerEnum, false);
|
||||
|
||||
innerEnum.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addFieldComment(org.mybatis.generator.api.dom.java.Field, org.mybatis.generator.api.IntrospectedTable, org.mybatis.generator.api.IntrospectedColumn)
|
||||
*/
|
||||
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
|
||||
|
||||
field.addJavaDocLine("/**");
|
||||
|
||||
String remarks = introspectedColumn.getRemarks();
|
||||
if (StringUtility.stringHasValue(remarks)) {
|
||||
field.addJavaDocLine(" * Database Column Remarks:");
|
||||
String[] remarkLines = remarks.split(System.getProperty("line.separator"));
|
||||
for (String remarkLine : remarkLines) {
|
||||
field.addJavaDocLine(" * " + remarkLine);
|
||||
}
|
||||
}
|
||||
|
||||
field.addJavaDocLine(" *");
|
||||
field.addJavaDocLine(" * This field was generated by MyBatis Generator.");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" * This field corresponds to the database column ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
sb.append('.');
|
||||
sb.append(introspectedColumn.getActualColumnName());
|
||||
field.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(field, false);
|
||||
|
||||
field.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addFieldComment(org.mybatis.generator.api.dom.java.Field, org.mybatis.generator.api.IntrospectedTable)
|
||||
*/
|
||||
public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
field.addJavaDocLine("/**");
|
||||
field.addJavaDocLine(" * This field was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This field corresponds to the database table ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
field.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(field, false);
|
||||
|
||||
field.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addGeneralMethodComment(org.mybatis.generator.api.dom.java.Method, org.mybatis.generator.api.IntrospectedTable)
|
||||
*/
|
||||
public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
method.addJavaDocLine("/**");
|
||||
method.addJavaDocLine(" * This method was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This method corresponds to the database table ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
method.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(method, false);
|
||||
|
||||
method.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addGetterComment(org.mybatis.generator.api.dom.java.Method, org.mybatis.generator.api.IntrospectedTable, org.mybatis.generator.api.IntrospectedColumn)
|
||||
*/
|
||||
public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
method.addJavaDocLine("/**");
|
||||
method.addJavaDocLine(" * This method was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This method returns the value of the database column ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
sb.append('.');
|
||||
sb.append(introspectedColumn.getActualColumnName());
|
||||
method.addJavaDocLine(sb.toString());
|
||||
|
||||
method.addJavaDocLine(" *");
|
||||
|
||||
sb.setLength(0);
|
||||
sb.append(" * @return the value of ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
sb.append('.');
|
||||
sb.append(introspectedColumn.getActualColumnName());
|
||||
method.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(method, false);
|
||||
|
||||
method.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addSetterComment(org.mybatis.generator.api.dom.java.Method, org.mybatis.generator.api.IntrospectedTable, org.mybatis.generator.api.IntrospectedColumn)
|
||||
*/
|
||||
public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
method.addJavaDocLine("/**");
|
||||
method.addJavaDocLine(" * This method was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This method sets the value of the database column ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
sb.append('.');
|
||||
sb.append(introspectedColumn.getActualColumnName());
|
||||
method.addJavaDocLine(sb.toString());
|
||||
|
||||
method.addJavaDocLine(" *");
|
||||
|
||||
Parameter parm = method.getParameters().get(0);
|
||||
sb.setLength(0);
|
||||
sb.append(" * @param ");
|
||||
sb.append(parm.getName());
|
||||
sb.append(" the value for ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
sb.append('.');
|
||||
sb.append(introspectedColumn.getActualColumnName());
|
||||
method.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(method, false);
|
||||
|
||||
method.addJavaDocLine(" */");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mybatis.generator.api.CommentGenerator#addClassComment(org.mybatis.generator.api.dom.java.InnerClass, org.mybatis.generator.api.IntrospectedTable, boolean)
|
||||
*/
|
||||
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
innerClass.addJavaDocLine("/**");
|
||||
innerClass.addJavaDocLine(" * This class was generated by MyBatis Generator.");
|
||||
|
||||
sb.append(" * This class corresponds to the database table ");
|
||||
sb.append(introspectedTable.getFullyQualifiedTable());
|
||||
innerClass.addJavaDocLine(sb.toString());
|
||||
|
||||
addJavadocTag(innerClass, markAsDoNotDelete);
|
||||
|
||||
innerClass.addJavaDocLine(" */");
|
||||
}
|
||||
}
|
||||
+18
@@ -56,4 +56,22 @@ public class InnerInterfaceWrapperToInnerClass extends InnerClass{
|
||||
public String getFormattedContent(int indentLevel, CompilationUnit compilationUnit) {
|
||||
return this.innerInterface.getFormattedContent(indentLevel, compilationUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property <tt>innerInterface</tt>.
|
||||
* @return property value of innerInterface
|
||||
* @author hewei
|
||||
*/
|
||||
public InnerInterface getInnerInterface() {
|
||||
return innerInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for property <tt>innerInterface</tt>.
|
||||
* @param innerInterface value to be assigned to property innerInterface
|
||||
* @author hewei
|
||||
*/
|
||||
public void setInnerInterface(InnerInterface innerInterface) {
|
||||
this.innerInterface = innerInterface;
|
||||
}
|
||||
}
|
||||
|
||||
+504
@@ -0,0 +1,504 @@
|
||||
/*
|
||||
* Copyright (c) 2017.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.itfsw.mybatis.generator.plugins.utils.enhanced;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.mybatis.generator.api.CommentGenerator;
|
||||
import org.mybatis.generator.api.IntrospectedColumn;
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.dom.java.*;
|
||||
import org.mybatis.generator.api.dom.xml.TextElement;
|
||||
import org.mybatis.generator.api.dom.xml.XmlElement;
|
||||
import org.mybatis.generator.config.MergeConstants;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* ---------------------------------------------------------------------------
|
||||
* 模板注释生成工具
|
||||
* ---------------------------------------------------------------------------
|
||||
* @author: hewei
|
||||
* @time:2017/6/8 13:21
|
||||
* ---------------------------------------------------------------------------
|
||||
*/
|
||||
public class TemplateCommentGenerator implements CommentGenerator {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(TemplateCommentGenerator.class); // 日志
|
||||
|
||||
private Map<EnumNode, Template> templates = new HashMap<>(); // 模板
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param templatePath 模板路径
|
||||
* @param useForDefault 未使用Comment插件,用作默认注释生成器
|
||||
*/
|
||||
public TemplateCommentGenerator(String templatePath, boolean useForDefault) {
|
||||
try {
|
||||
Document doc = null;
|
||||
if (useForDefault){
|
||||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(templatePath);
|
||||
doc = new SAXReader().read(inputStream);
|
||||
} else {
|
||||
File file = new File(templatePath);
|
||||
if (file.exists()) {
|
||||
doc = new SAXReader().read(file);
|
||||
} else {
|
||||
logger.error("没有找到对应注释模板:" + templatePath);
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历comment 节点
|
||||
if (doc != null){
|
||||
for (EnumNode node : EnumNode.values()){
|
||||
Element element = doc.getRootElement().elementByID(node.value());
|
||||
if (element != null){
|
||||
Configuration cfg = new Configuration();
|
||||
// 字符串清理
|
||||
Template template = new Template(node.value(), element.getText(), cfg);
|
||||
templates.put(node, template);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("注释模板XML解析失败!", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取评论
|
||||
* @param map 模板参数
|
||||
* @param node 节点ID
|
||||
* @return
|
||||
*/
|
||||
private String[] getComments(Map<String, Object> map, EnumNode node) {
|
||||
// 1. 模板引擎解析
|
||||
try {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
Template template = templates.get(node);
|
||||
if (template != null){
|
||||
template.process(map, stringWriter);
|
||||
|
||||
String comment = stringWriter.toString();
|
||||
stringWriter.close();
|
||||
|
||||
// 需要先清理字符串
|
||||
return comment.replaceFirst("^[\\s\\t\\r\\n]*", "").replaceFirst("[\\s\\t\\r\\n]*$", "").split("\n");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("freemarker 解析失败!", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加评论
|
||||
*
|
||||
* @param javaElement
|
||||
* @param map
|
||||
* @param node
|
||||
*/
|
||||
private void addJavaElementComment(JavaElement javaElement, Map<String, Object> map, EnumNode node) {
|
||||
// 获取评论
|
||||
String[] comments = getComments(map, node);
|
||||
if (comments != null){
|
||||
// 去除空评论
|
||||
if (comments.length == 1 && !StringUtility.stringHasValue(comments[0])){
|
||||
return;
|
||||
}
|
||||
// 添加评论
|
||||
for (String comment : comments){
|
||||
javaElement.addJavaDocLine(comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加评论
|
||||
*
|
||||
* @param compilationUnit
|
||||
* @param map
|
||||
* @param node
|
||||
*/
|
||||
private void addCompilationUnitComment(CompilationUnit compilationUnit, Map<String, Object> map, EnumNode node) {
|
||||
// 获取评论
|
||||
String[] comments = getComments(map, node);
|
||||
if (comments != null){
|
||||
// 去除空评论
|
||||
if (comments.length == 1 && !StringUtility.stringHasValue(comments[0])){
|
||||
return;
|
||||
}
|
||||
// 添加评论
|
||||
for (String comment : comments){
|
||||
compilationUnit.addFileCommentLine(comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加评论
|
||||
*
|
||||
* @param xmlElement
|
||||
* @param map
|
||||
* @param node
|
||||
*/
|
||||
private void addXmlElementComment(XmlElement xmlElement, Map<String, Object> map, EnumNode node) {
|
||||
// 获取评论
|
||||
String[] comments = getComments(map, node);
|
||||
if (comments != null){
|
||||
// 去除空评论
|
||||
if (comments.length == 1 && !StringUtility.stringHasValue(comments[0])){
|
||||
return;
|
||||
}
|
||||
// 添加评论
|
||||
for (String comment : comments){
|
||||
xmlElement.addElement(new TextElement(comment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds properties for this instance from any properties configured in the
|
||||
* CommentGenerator configuration.
|
||||
*
|
||||
* This method will be called before any of the other methods.
|
||||
*
|
||||
* @param properties
|
||||
* All properties from the configuration
|
||||
*/
|
||||
@Override
|
||||
public void addConfigurationProperties(Properties properties) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should add a Javadoc comment to the specified field. The field is related to the specified table and
|
||||
* is used to hold the value of the specified column.
|
||||
* <p>
|
||||
*
|
||||
* <b>Important:</b> This method should add a the nonstandard JavaDoc tag "@mbg.generated" to the comment. Without
|
||||
* this tag, the Eclipse based Java merge feature will fail.
|
||||
*
|
||||
* @param field
|
||||
* the field
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
@Override
|
||||
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("field", field);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
map.put("introspectedColumn", introspectedColumn);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(field, map, EnumNode.ADD_FIELD_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the field comment.
|
||||
*
|
||||
* @param field
|
||||
* the field
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
@Override
|
||||
public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("field", field);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(field, map, EnumNode.ADD_FIELD_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a comment for a model class. The Java code merger should
|
||||
* be notified not to delete the entire class in case any manual
|
||||
* changes have been made. So this method will always use the
|
||||
* "do not delete" annotation.
|
||||
*
|
||||
* Because of difficulties with the Java file merger, the default implementation
|
||||
* of this method should NOT add comments. Comments should only be added if
|
||||
* specifically requested by the user (for example, by enabling table remark comments).
|
||||
*
|
||||
* @param topLevelClass
|
||||
* the top level class
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
@Override
|
||||
public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("topLevelClass", topLevelClass);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(topLevelClass, map, EnumNode.ADD_MODEL_CLASS_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the inner class comment.
|
||||
*
|
||||
* @param innerClass
|
||||
* the inner class
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
@Override
|
||||
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
|
||||
if (innerClass instanceof InnerInterfaceWrapperToInnerClass){
|
||||
InnerInterface innerInterface = ((InnerInterfaceWrapperToInnerClass)innerClass).getInnerInterface();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("innerInterface", innerInterface);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(innerInterface, map, EnumNode.ADD_INTERFACE_COMMENT);
|
||||
} else {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("innerClass", innerClass);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(innerClass, map, EnumNode.ADD_CLASS_COMMENT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the inner class comment.
|
||||
*
|
||||
* @param innerClass
|
||||
* the inner class
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param markAsDoNotDelete
|
||||
* the mark as do not delete
|
||||
*/
|
||||
@Override
|
||||
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("innerClass", innerClass);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
map.put("markAsDoNotDelete", markAsDoNotDelete);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(innerClass, map, EnumNode.ADD_CLASS_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the enum comment.
|
||||
*
|
||||
* @param innerEnum
|
||||
* the inner enum
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
@Override
|
||||
public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("innerEnum", innerEnum);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(innerEnum, map, EnumNode.ADD_ENUM_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the getter comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
@Override
|
||||
public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("method", method);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
map.put("introspectedColumn", introspectedColumn);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(method, map, EnumNode.ADD_GETTER_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the setter comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
@Override
|
||||
public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("method", method);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
map.put("introspectedColumn", introspectedColumn);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(method, map, EnumNode.ADD_SETTER_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the general method comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
@Override
|
||||
public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("method", method);
|
||||
map.put("introspectedTable", introspectedTable);
|
||||
|
||||
// 添加评论
|
||||
addJavaElementComment(method, map, EnumNode.ADD_GENERAL_METHOD_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to add a file level comment to a generated java file. This method could be used to add a
|
||||
* general file comment (such as a copyright notice). However, note that the Java file merge function in Eclipse
|
||||
* does not deal with this comment. If you run the generator repeatedly, you will only retain the comment from the
|
||||
* initial run.
|
||||
* <p>
|
||||
*
|
||||
* The default implementation does nothing.
|
||||
*
|
||||
* @param compilationUnit
|
||||
* the compilation unit
|
||||
*/
|
||||
@Override
|
||||
public void addJavaFileComment(CompilationUnit compilationUnit) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("compilationUnit", compilationUnit);
|
||||
|
||||
// 添加评论
|
||||
addCompilationUnitComment(compilationUnit, map, EnumNode.ADD_JAVA_FILE_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should add a suitable comment as a child element of the specified xmlElement to warn users that the
|
||||
* element was generated and is subject to regeneration.
|
||||
*
|
||||
* @param xmlElement
|
||||
* the xml element
|
||||
*/
|
||||
@Override
|
||||
public void addComment(XmlElement xmlElement) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("xmlElement", xmlElement);
|
||||
|
||||
// 添加评论
|
||||
addXmlElementComment(xmlElement, map, EnumNode.ADD_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to add a comment as the first child of the root element. This method could be used to add a
|
||||
* general file comment (such as a copyright notice). However, note that the XML file merge function does not deal
|
||||
* with this comment. If you run the generator repeatedly, you will only retain the comment from the initial run.
|
||||
* <p>
|
||||
*
|
||||
* The default implementation does nothing.
|
||||
*
|
||||
* @param rootElement
|
||||
* the root element
|
||||
*/
|
||||
@Override
|
||||
public void addRootComment(XmlElement rootElement) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
|
||||
map.put("rootElement", rootElement);
|
||||
|
||||
// 添加评论
|
||||
addXmlElementComment(rootElement, map, EnumNode.ADD_ROOT_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论模板节点ID
|
||||
*/
|
||||
public static enum EnumNode {
|
||||
ADD_COMMENT("addComment"), // Xml 节点注释
|
||||
ADD_ROOT_COMMENT("addRootComment"), // xml root 节点注释
|
||||
ADD_JAVA_FILE_COMMENT("addJavaFileComment"), // java 文件注释
|
||||
ADD_GENERAL_METHOD_COMMENT("addGeneralMethodComment"), // java 方法注释
|
||||
ADD_SETTER_COMMENT("addSetterComment"), // setter 方法注释
|
||||
ADD_GETTER_COMMENT("addGetterComment"), // getter 方式注释
|
||||
ADD_ENUM_COMMENT("addEnumComment"), // 枚举 注释
|
||||
ADD_CLASS_COMMENT("addClassComment"), // 类 注释
|
||||
ADD_INTERFACE_COMMENT("addInterfaceComment"), // 接口 注释
|
||||
ADD_MODEL_CLASS_COMMENT("addModelClassComment"), // model 类注释
|
||||
ADD_FIELD_COMMENT("addFieldComment"), // 字段 注释
|
||||
;
|
||||
|
||||
private final String value; // 值
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param value
|
||||
*/
|
||||
EnumNode(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 值
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String value(){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method is called to add a file level comment to a generated java file. This method could be used to add a
|
||||
* general file comment (such as a copyright notice). However, note that the Java file merge function in Eclipse
|
||||
* does not deal with this comment. If you run the generator repeatedly, you will only retain the comment from the
|
||||
* initial run.
|
||||
* <p>
|
||||
*
|
||||
* The default implementation does nothing.
|
||||
*
|
||||
* @param compilationUnit
|
||||
* the compilation unit
|
||||
*/
|
||||
-->
|
||||
<comment ID="addJavaFileComment"></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method should add a suitable comment as a child element of the specified xmlElement to warn users that the
|
||||
* element was generated and is subject to regeneration.
|
||||
*
|
||||
* @param xmlElement
|
||||
* the xml element
|
||||
*/
|
||||
-->
|
||||
<comment ID="addComment"><![CDATA[
|
||||
<!--
|
||||
WARNING - ${mgb}
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
@project https://github.com/itfsw/mybatis-generator-plugin
|
||||
-->
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method is called to add a comment as the first child of the root element. This method could be used to add a
|
||||
* general file comment (such as a copyright notice). However, note that the XML file merge function does not deal
|
||||
* with this comment. If you run the generator repeatedly, you will only retain the comment from the initial run.
|
||||
* <p>
|
||||
*
|
||||
* The default implementation does nothing.
|
||||
*
|
||||
* @param rootElement
|
||||
* the root element
|
||||
*/
|
||||
-->
|
||||
<comment ID="addRootComment"></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* This method should add a Javadoc comment to the specified field. The field is related to the specified table and
|
||||
* is used to hold the value of the specified column.
|
||||
* <p>
|
||||
*
|
||||
* <b>Important:</b> This method should add a the nonstandard JavaDoc tag "@mbg.generated" to the comment. Without
|
||||
* this tag, the Eclipse based Java merge feature will fail.
|
||||
*
|
||||
* @param field
|
||||
* the field
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
-->
|
||||
<comment ID="addFieldComment"><![CDATA[
|
||||
<#if introspectedColumn??>
|
||||
/**
|
||||
<#if introspectedColumn.remarks?? && introspectedColumn.remarks != ''>
|
||||
* Database Column Remarks:
|
||||
<#list introspectedColumn.remarks?split("\n") as remark>
|
||||
* ${remark}
|
||||
</#list>
|
||||
</#if>
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
<#else>
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
</#if>
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds a comment for a model class. The Java code merger should
|
||||
* be notified not to delete the entire class in case any manual
|
||||
* changes have been made. So this method will always use the
|
||||
* "do not delete" annotation.
|
||||
*
|
||||
* Because of difficulties with the Java file merger, the default implementation
|
||||
* of this method should NOT add comments. Comments should only be added if
|
||||
* specifically requested by the user (for example, by enabling table remark comments).
|
||||
*
|
||||
* @param topLevelClass
|
||||
* the top level class
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addModelClassComment"><![CDATA[
|
||||
/**
|
||||
<#if introspectedTable.remarks?? && introspectedTable.remarks != ''>
|
||||
* Database Table Remarks:
|
||||
<#list introspectedTable.remarks?split("\n") as remark>
|
||||
* ${remark}
|
||||
</#list>
|
||||
</#if>
|
||||
*
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb} do_not_delete_during_merge
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the inner class comment.
|
||||
*
|
||||
* @param innerClass
|
||||
* the inner class
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param markAsDoNotDelete
|
||||
* the mark as do not delete
|
||||
*/
|
||||
-->
|
||||
<comment ID="addClassComment"><![CDATA[
|
||||
/**
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}<#if markAsDoNotDelete?? && markAsDoNotDelete> do_not_delete_during_merge</#if>
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the enum comment.
|
||||
*
|
||||
* @param innerEnum
|
||||
* the inner enum
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addEnumComment"><![CDATA[
|
||||
/**
|
||||
* This enum was generated by MyBatis Generator.
|
||||
* This enum corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the interface comment.
|
||||
*
|
||||
* @param innerInterface
|
||||
* the inner interface
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addInterfaceComment"><![CDATA[
|
||||
/**
|
||||
* This interface was generated by MyBatis Generator.
|
||||
* This interface corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the getter comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
-->
|
||||
<comment ID="addGetterComment"><![CDATA[
|
||||
<#if introspectedColumn??>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* @return the value of ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
<#else>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the field ${method.name?replace("get","")?replace("is", "")?uncap_first}
|
||||
*
|
||||
* @return the value of field ${method.name?replace("get","")?replace("is", "")?uncap_first}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
</#if>
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the setter comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
* @param introspectedColumn
|
||||
* the introspected column
|
||||
*/
|
||||
-->
|
||||
<comment ID="addSetterComment"><![CDATA[
|
||||
<#if introspectedColumn??>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* @param ${method.parameters[0].name} the value for ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
<#else>
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the field ${method.name?replace("set","")?uncap_first}
|
||||
*
|
||||
* @param ${method.parameters[0].name} the value for field ${method.name?replace("set","")?uncap_first}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
</#if>
|
||||
]]></comment>
|
||||
|
||||
<!-- #############################################################################################################
|
||||
/**
|
||||
* Adds the general method comment.
|
||||
*
|
||||
* @param method
|
||||
* the method
|
||||
* @param introspectedTable
|
||||
* the introspected table
|
||||
*/
|
||||
-->
|
||||
<comment ID="addGeneralMethodComment"><![CDATA[
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table ${introspectedTable.fullyQualifiedTable}
|
||||
*
|
||||
* ${mgb}
|
||||
* @project https://github.com/itfsw/mybatis-generator-plugin
|
||||
*/
|
||||
]]></comment>
|
||||
</template>
|
||||
Reference in New Issue
Block a user