Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mybatis-generator-plugin
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mybatis-generator-plugin
Commits
6a153b23
Commit
6a153b23
authored
Apr 28, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
一些代码精简
parent
ce96a44f
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
527 additions
and
445 deletions
+527
-445
src/main/java/com/itfsw/mybatis/generator/plugins/BatchInsertOldPlugin.java
...itfsw/mybatis/generator/plugins/BatchInsertOldPlugin.java
+7
-18
src/main/java/com/itfsw/mybatis/generator/plugins/BatchInsertPlugin.java
...om/itfsw/mybatis/generator/plugins/BatchInsertPlugin.java
+7
-17
src/main/java/com/itfsw/mybatis/generator/plugins/CriteriaBuilderPlugin.java
...tfsw/mybatis/generator/plugins/CriteriaBuilderPlugin.java
+0
-5
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
...tfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
+12
-30
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleTargetPlugin.java
.../itfsw/mybatis/generator/plugins/ExampleTargetPlugin.java
+3
-13
src/main/java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
...java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
+24
-23
src/main/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePlugin.java
.../itfsw/mybatis/generator/plugins/LogicalDeletePlugin.java
+13
-29
src/main/java/com/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
...m/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
+37
-45
src/main/java/com/itfsw/mybatis/generator/plugins/ModelColumnPlugin.java
...om/itfsw/mybatis/generator/plugins/ModelColumnPlugin.java
+9
-27
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
...w/mybatis/generator/plugins/SelectOneByExamplePlugin.java
+4
-24
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
...sw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
+7
-17
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
...ava/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
+11
-25
src/main/java/com/itfsw/mybatis/generator/plugins/utils/BasePlugin.java
...com/itfsw/mybatis/generator/plugins/utils/BasePlugin.java
+52
-0
src/main/java/com/itfsw/mybatis/generator/plugins/utils/CommentTools.java
...m/itfsw/mybatis/generator/plugins/utils/CommentTools.java
+0
-155
src/main/java/com/itfsw/mybatis/generator/plugins/utils/JavaElementGeneratorTools.java
...is/generator/plugins/utils/JavaElementGeneratorTools.java
+6
-17
src/main/java/com/itfsw/mybatis/generator/plugins/utils/enhanced/IWCommentGenerator.java
.../generator/plugins/utils/enhanced/IWCommentGenerator.java
+335
-0
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/BatchInsertOldPlugin.java
View file @
6a153b23
...
...
@@ -16,11 +16,10 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.CommentTools
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Document
;
...
...
@@ -30,9 +29,6 @@ import org.mybatis.generator.codegen.mybatis3.ListUtilities;
import
org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities
;
import
org.mybatis.generator.config.Context
;
import
org.mybatis.generator.config.PluginConfiguration
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -46,8 +42,7 @@ import java.util.List;
* ---------------------------------------------------------------------------
*/
@Deprecated
public
class
BatchInsertOldPlugin
extends
PluginAdapter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BatchInsertOldPlugin
.
class
);
public
class
BatchInsertOldPlugin
extends
BasePlugin
{
public
static
final
String
METHOD_BATCH_INSERT
=
"batchInsert"
;
// 方法名
private
boolean
hasModelBuilderPlugin
;
// 是否配置了ModelBuilderPlugin插件
...
...
@@ -56,12 +51,6 @@ public class BatchInsertOldPlugin extends PluginAdapter {
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
// 插件使用前提是数据库为MySQL或者SQLserver,因为返回主键使用了JDBC的getGenereatedKeys方法获取主键
if
(
"com.mysql.jdbc.Driver"
.
equalsIgnoreCase
(
this
.
getContext
().
getJdbcConnectionConfiguration
().
getDriverClass
())
==
false
&&
"com.microsoft.jdbc.sqlserver.SQLServer"
.
equalsIgnoreCase
(
this
.
getContext
().
getJdbcConnectionConfiguration
().
getDriverClass
())
==
false
...
...
@@ -72,7 +61,7 @@ public class BatchInsertOldPlugin extends PluginAdapter {
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"插件已过期,不再维护请使用com.itfsw.mybatis.generator.plugins.BatchInsertPlugin区分batchInsert和batchInsertSelective!"
);
return
true
;
return
super
.
validate
(
warnings
)
;
}
/**
...
...
@@ -125,7 +114,7 @@ public class BatchInsertOldPlugin extends PluginAdapter {
FullyQualifiedJavaType
type1
=
new
FullyQualifiedJavaType
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
().
getShortName
()+
"."
+
ModelColumnPlugin
.
ENUM_NAME
);
method
.
addParameter
(
new
Parameter
(
type1
,
"insertColumns"
,
"@Param(\"insertColumns\")"
,
true
));
// 添加方法说明
CommentTools
.
add
MethodComment
(
method
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
method
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
method
);
...
...
@@ -142,7 +131,7 @@ public class BatchInsertOldPlugin extends PluginAdapter {
type
.
addTypeArgument
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
());
method
.
addParameter
(
new
Parameter
(
type
,
"list"
,
"@Param(\"list\")"
));
// 添加方法说明
CommentTools
.
add
MethodComment
(
method
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
method
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
method
);
...
...
@@ -168,7 +157,7 @@ public class BatchInsertOldPlugin extends PluginAdapter {
// 参数类型
element
.
addAttribute
(
new
Attribute
(
"parameterType"
,
"map"
));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
element
);
commentGenerator
.
addComment
(
element
);
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
XmlElementGeneratorTools
.
useGeneratedKeys
(
element
,
introspectedTable
);
...
...
@@ -243,7 +232,7 @@ public class BatchInsertOldPlugin extends PluginAdapter {
element
.
addAttribute
(
new
Attribute
(
"parameterType"
,
FullyQualifiedJavaType
.
getNewListInstance
().
getFullyQualifiedName
()));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
element
);
commentGenerator
.
addComment
(
element
);
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
XmlElementGeneratorTools
.
useGeneratedKeys
(
element
,
introspectedTable
);
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/BatchInsertPlugin.java
View file @
6a153b23
...
...
@@ -16,13 +16,12 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.
CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.
BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.PluginTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Document
;
...
...
@@ -30,9 +29,6 @@ import org.mybatis.generator.api.dom.xml.TextElement;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
org.mybatis.generator.codegen.mybatis3.ListUtilities
;
import
org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
...
...
@@ -44,8 +40,7 @@ import java.util.List;
* @time:2017/1/13 9:33
* ---------------------------------------------------------------------------
*/
public
class
BatchInsertPlugin
extends
PluginAdapter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BatchInsertPlugin
.
class
);
public
class
BatchInsertPlugin
extends
BasePlugin
{
public
static
final
String
METHOD_BATCH_INSERT
=
"batchInsert"
;
// 方法名
public
static
final
String
METHOD_BATCH_INSERT_SELECTIVE
=
"batchInsertSelective"
;
// 方法名
...
...
@@ -54,11 +49,6 @@ public class BatchInsertPlugin extends PluginAdapter {
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
// 插件使用前提是数据库为MySQL或者SQLserver,因为返回主键使用了JDBC的getGenereatedKeys方法获取主键
if
(
"com.mysql.jdbc.Driver"
.
equalsIgnoreCase
(
this
.
getContext
().
getJdbcConnectionConfiguration
().
getDriverClass
())
==
false
...
...
@@ -78,7 +68,7 @@ public class BatchInsertPlugin extends PluginAdapter {
// TODO
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"插件如之前使用1.0.5-的插件可继续使用com.itfsw.mybatis.generator.plugins.BatchInsertOldPlugin或者修改batchInsert(@Param(\"list\") List<Tb> list, @Param(\"insertColumns\") Tb.Column ... selective)调用为batchInsertSelective!"
);
return
true
;
return
super
.
validate
(
warnings
)
;
}
...
...
@@ -101,10 +91,10 @@ public class BatchInsertPlugin extends PluginAdapter {
METHOD_BATCH_INSERT
,
JavaVisibility
.
DEFAULT
,
FullyQualifiedJavaType
.
getIntInstance
(),
introspectedTable
,
new
Parameter
(
listType
,
"list"
,
"@Param(\"list\")"
)
);
commentGenerator
.
addGeneralMethodComment
(
mBatchInsert
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mBatchInsert
);
logger
.
debug
(
"itfsw(批量插入插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加batchInsert方法。"
);
...
...
@@ -115,10 +105,10 @@ public class BatchInsertPlugin extends PluginAdapter {
METHOD_BATCH_INSERT_SELECTIVE
,
JavaVisibility
.
DEFAULT
,
FullyQualifiedJavaType
.
getIntInstance
(),
introspectedTable
,
new
Parameter
(
listType
,
"list"
,
"@Param(\"list\")"
),
new
Parameter
(
selectiveType
,
"selective"
,
"@Param(\"selective\")"
,
true
)
);
commentGenerator
.
addGeneralMethodComment
(
mBatchInsertSelective
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mBatchInsertSelective
);
logger
.
debug
(
"itfsw(批量插入插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加batchInsertSelective方法。"
);
...
...
@@ -142,7 +132,7 @@ public class BatchInsertPlugin extends PluginAdapter {
// 参数类型
batchInsertEle
.
addAttribute
(
new
Attribute
(
"parameterType"
,
"map"
));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
batchInsertEle
);
commentGenerator
.
addComment
(
batchInsertEle
);
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
XmlElementGeneratorTools
.
useGeneratedKeys
(
batchInsertEle
,
introspectedTable
);
...
...
@@ -173,7 +163,7 @@ public class BatchInsertPlugin extends PluginAdapter {
// 参数类型
element
.
addAttribute
(
new
Attribute
(
"parameterType"
,
"map"
));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
element
);
commentGenerator
.
addComment
(
element
);
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
XmlElementGeneratorTools
.
useGeneratedKeys
(
element
,
introspectedTable
);
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/CriteriaBuilderPlugin.java
View file @
6a153b23
...
...
@@ -16,9 +16,6 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
/**
...
...
@@ -31,8 +28,6 @@ import java.util.List;
*/
@Deprecated
public
class
CriteriaBuilderPlugin
extends
ExampleEnhancedPlugin
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CriteriaBuilderPlugin
.
class
);
/**
* {@inheritDoc}
*/
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
View file @
6a153b23
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.
CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.
BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.enhanced.InnerInterface
;
import
com.itfsw.mybatis.generator.plugins.utils.enhanced.InnerInterfaceWrapperToInnerClass
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
...
...
@@ -21,21 +17,7 @@ import java.util.List;
* @time:2017/1/16 16:28
* ---------------------------------------------------------------------------
*/
public
class
ExampleEnhancedPlugin
extends
PluginAdapter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ExampleEnhancedPlugin
.
class
);
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
return
true
;
}
public
class
ExampleEnhancedPlugin
extends
BasePlugin
{
/**
* ModelExample Methods 生成
...
...
@@ -82,9 +64,9 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
"example"
,
JavaVisibility
.
PRIVATE
,
topLevelClass
.
getType
(),
null
,
introspectedTable
null
);
commentGenerator
.
addFieldComment
(
exampleField
,
introspectedTable
);
innerClass
.
addField
(
exampleField
);
// overwrite constructor
...
...
@@ -93,7 +75,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
if
(
method
.
isConstructor
())
{
method
.
addParameter
(
new
Parameter
(
topLevelClass
.
getType
(),
"example"
));
method
.
addBodyLine
(
"this.example = example;"
);
CommentTools
.
add
MethodComment
(
method
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
method
,
introspectedTable
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"修改构造方法,增加example参数"
);
}
}
...
...
@@ -102,9 +84,9 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
Method
exampleMethod
=
JavaElementGeneratorTools
.
generateMethod
(
"example"
,
JavaVisibility
.
PUBLIC
,
topLevelClass
.
getType
(),
introspectedTable
topLevelClass
.
getType
()
);
commentGenerator
.
addGeneralMethodComment
(
exampleMethod
,
introspectedTable
);
exampleMethod
=
JavaElementGeneratorTools
.
generateMethodBody
(
exampleMethod
,
"return this.example;"
...
...
@@ -124,7 +106,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
// 添加接口CriteriaAdd
InnerInterface
criteriaAddInterface
=
new
InnerInterface
(
"ICriteriaAdd"
);
criteriaAddInterface
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
CommentTools
.
addInterfaceComment
(
criteriaAddInterface
,
introspectedTable
);
commentGenerator
.
addInterfaceComment
(
criteriaAddInterface
,
introspectedTable
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"."
+
innerClass
.
getType
().
getShortName
()
+
"增加接口ICriteriaAdd"
);
// ICriteriaAdd增加接口add
...
...
@@ -132,9 +114,9 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
"add"
,
JavaVisibility
.
DEFAULT
,
innerClass
.
getType
(),
introspectedTable
,
new
Parameter
(
innerClass
.
getType
(),
"add"
)
);
commentGenerator
.
addGeneralMethodComment
(
addMethod
,
introspectedTable
);
criteriaAddInterface
.
addMethod
(
addMethod
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"."
+
innerClass
.
getType
().
getShortName
()
+
"."
+
criteriaAddInterface
.
getType
().
getShortName
()
+
"增加方法add"
);
...
...
@@ -146,10 +128,10 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
"andIf"
,
JavaVisibility
.
PUBLIC
,
innerClass
.
getType
(),
introspectedTable
,
new
Parameter
(
FullyQualifiedJavaType
.
getBooleanPrimitiveInstance
(),
"ifAdd"
),
new
Parameter
(
criteriaAddInterface
.
getType
(),
"add"
)
);
commentGenerator
.
addGeneralMethodComment
(
andIfMethod
,
introspectedTable
);
andIfMethod
=
JavaElementGeneratorTools
.
generateMethodBody
(
andIfMethod
,
"if (ifAdd) {"
,
...
...
@@ -172,9 +154,9 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
"orderBy"
,
JavaVisibility
.
PUBLIC
,
topLevelClass
.
getType
(),
introspectedTable
,
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"orderByClause"
)
);
commentGenerator
.
addGeneralMethodComment
(
orderByMethod
,
introspectedTable
);
orderByMethod
=
JavaElementGeneratorTools
.
generateMethodBody
(
orderByMethod
,
"this.setOrderByClause(orderByClause);"
,
...
...
@@ -188,9 +170,9 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
"orderBy"
,
JavaVisibility
.
PUBLIC
,
topLevelClass
.
getType
(),
introspectedTable
,
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"orderByClauses"
,
true
)
);
commentGenerator
.
addGeneralMethodComment
(
orderByMethod1
,
introspectedTable
);
orderByMethod1
=
JavaElementGeneratorTools
.
generateMethodBody
(
orderByMethod1
,
"StringBuffer sb = new StringBuffer();"
,
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleTargetPlugin.java
View file @
6a153b23
...
...
@@ -18,13 +18,10 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.config.Context
;
import
org.mybatis.generator.config.JavaModelGeneratorConfiguration
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
import
java.util.Properties
;
...
...
@@ -37,10 +34,8 @@ import java.util.Properties;
* @time:2017/1/12 12:36
* ---------------------------------------------------------------------------
*/
public
class
ExampleTargetPlugin
extends
PluginAdapter
{
public
class
ExampleTargetPlugin
extends
BasePlugin
{
public
static
final
String
TARGET_PACKAGE_KEY
=
"targetPackage"
;
// 配置targetPackage名
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ExampleTargetPlugin
.
class
);
private
static
String
targetPackage
;
// 目标包
/**
...
...
@@ -48,11 +43,6 @@ public class ExampleTargetPlugin extends PluginAdapter {
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
){
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
// 获取配置的目标package
Properties
properties
=
getProperties
();
this
.
targetPackage
=
properties
.
getProperty
(
TARGET_PACKAGE_KEY
);
...
...
@@ -60,7 +50,7 @@ public class ExampleTargetPlugin extends PluginAdapter {
logger
.
warn
(
"请配置com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin插件的目标包名(targetPackage)!"
);
return
false
;
}
return
true
;
return
super
.
validate
(
warnings
)
;
}
/**
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
View file @
6a153b23
...
...
@@ -16,16 +16,13 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.TextElement
;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
...
...
@@ -37,24 +34,18 @@ import java.util.List;
* @time:2016/12/29 18:14
* ---------------------------------------------------------------------------
*/
public
class
LimitPlugin
extends
PluginAdapter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LimitPlugin
.
class
);
public
class
LimitPlugin
extends
BasePlugin
{
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
){
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
// 该插件只支持MYSQL
if
(
"com.mysql.jdbc.Driver"
.
equalsIgnoreCase
(
this
.
getContext
().
getJdbcConnectionConfiguration
().
getDriverClass
())
==
false
){
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()+
"只支持MySQL数据库!"
);
return
false
;
}
return
true
;
return
super
.
validate
(
warnings
)
;
}
/**
...
...
@@ -73,27 +64,37 @@ public class LimitPlugin extends PluginAdapter {
"offset"
,
JavaVisibility
.
PROTECTED
,
integerWrapper
,
null
,
introspectedTable
null
);
commentGenerator
.
addFieldComment
(
offsetField
,
introspectedTable
);
topLevelClass
.
addField
(
offsetField
);
Field
rowsField
=
JavaElementGeneratorTools
.
generateField
(
"rows"
,
JavaVisibility
.
PROTECTED
,
integerWrapper
,
null
,
introspectedTable
null
);
commentGenerator
.
addFieldComment
(
rowsField
,
introspectedTable
);
topLevelClass
.
addField
(
rowsField
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加offset和rows字段"
);
// 增加getter && setter 方法
topLevelClass
.
addMethod
(
JavaElementGeneratorTools
.
generateSetterMethod
(
offsetField
,
introspectedTable
));
topLevelClass
.
addMethod
(
JavaElementGeneratorTools
.
generateGetterMethod
(
offsetField
,
introspectedTable
));
Method
mSetOffset
=
JavaElementGeneratorTools
.
generateSetterMethod
(
offsetField
);
commentGenerator
.
addGeneralMethodComment
(
mSetOffset
,
introspectedTable
);
topLevelClass
.
addMethod
(
mSetOffset
);
Method
mGetOffset
=
JavaElementGeneratorTools
.
generateGetterMethod
(
offsetField
);
commentGenerator
.
addGeneralMethodComment
(
mGetOffset
,
introspectedTable
);
topLevelClass
.
addMethod
(
mGetOffset
);
Method
mSetRows
=
JavaElementGeneratorTools
.
generateSetterMethod
(
rowsField
);
commentGenerator
.
addGeneralMethodComment
(
mSetRows
,
introspectedTable
);
topLevelClass
.
addMethod
(
mSetRows
);
topLevelClass
.
addMethod
(
JavaElementGeneratorTools
.
generateSetterMethod
(
rowsField
,
introspectedTable
));
topLevelClass
.
addMethod
(
JavaElementGeneratorTools
.
generateGetterMethod
(
rowsField
,
introspectedTable
));
Method
mGetRows
=
JavaElementGeneratorTools
.
generateGetterMethod
(
rowsField
);
commentGenerator
.
addGeneralMethodComment
(
mGetRows
,
introspectedTable
);
topLevelClass
.
addMethod
(
mGetRows
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加offset和rows的getter和setter实现。"
);
// 提供几个快捷方法
...
...
@@ -101,9 +102,9 @@ public class LimitPlugin extends PluginAdapter {
"limit"
,
JavaVisibility
.
PUBLIC
,
topLevelClass
.
getType
(),
introspectedTable
,
new
Parameter
(
integerWrapper
,
"rows"
)
);
commentGenerator
.
addGeneralMethodComment
(
setLimit
,
introspectedTable
);
setLimit
=
JavaElementGeneratorTools
.
generateMethodBody
(
setLimit
,
"this.rows = rows;"
,
...
...
@@ -115,10 +116,10 @@ public class LimitPlugin extends PluginAdapter {
"limit"
,
JavaVisibility
.
PUBLIC
,
topLevelClass
.
getType
(),
introspectedTable
,
new
Parameter
(
integerWrapper
,
"offset"
),
new
Parameter
(
integerWrapper
,
"rows"
)
);
commentGenerator
.
addGeneralMethodComment
(
setLimit2
,
introspectedTable
);
setLimit2
=
JavaElementGeneratorTools
.
generateMethodBody
(
setLimit2
,
"this.offset = offset;"
,
...
...
@@ -132,10 +133,10 @@ public class LimitPlugin extends PluginAdapter {
"page"
,
JavaVisibility
.
PUBLIC
,
topLevelClass
.
getType
(),
introspectedTable
,
new
Parameter
(
integerWrapper
,
"page"
),
new
Parameter
(
integerWrapper
,
"pageSize"
)
);
commentGenerator
.
addGeneralMethodComment
(
setPage
,
introspectedTable
);
setPage
=
JavaElementGeneratorTools
.
generateMethodBody
(
setPage
,
"this.offset = page * pageSize;"
,
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePlugin.java
View file @
6a153b23
...
...
@@ -16,21 +16,17 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.
CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.
BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Document
;
import
org.mybatis.generator.api.dom.xml.TextElement
;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.sql.JDBCType
;
import
java.util.*
;
...
...
@@ -43,9 +39,7 @@ import java.util.*;
* @time:2017/1/13 14:08
* ---------------------------------------------------------------------------
*/
public
class
LogicalDeletePlugin
extends
PluginAdapter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LogicalDeletePlugin
.
class
);
public
class
LogicalDeletePlugin
extends
BasePlugin
{
public
static
final
String
METHOD_LOGICAL_DELETE_BY_EXAMPLE
=
"logicalDeleteByExample"
;
// 方法名
public
static
final
String
METHOD_LOGICAL_DELETE_BY_PRIMARY_KEY
=
"logicalDeleteByPrimaryKey"
;
// 方法名
...
...
@@ -62,19 +56,6 @@ public class LogicalDeletePlugin extends PluginAdapter {
private
String
logicalDeleteValue
;
// 逻辑删除值
private
String
logicalUnDeleteValue
;
// 逻辑删除值(未删除)
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
){
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
return
true
;
}
/**
* 初始化阶段
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
...
...
@@ -159,7 +140,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
FullyQualifiedJavaType
type
=
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
());
mLogicalDeleteByExample
.
addParameter
(
new
Parameter
(
type
,
"example"
));
// 添加方法说明
CommentTools
.
add
MethodComment
(
mLogicalDeleteByExample
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
mLogicalDeleteByExample
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mLogicalDeleteByExample
);
logger
.
debug
(
"itfsw(逻辑删除插件):"
+
interfaze
.
getType
().
getShortName
()+
"增加方法logicalDeleteByExample。"
);
...
...
@@ -204,7 +185,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
}
// 添加方法说明
CommentTools
.
add
MethodComment
(
mLogicalDeleteByPrimaryKey
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
mLogicalDeleteByPrimaryKey
,
introspectedTable
);
// interface 增加方法
interfaze
.
addImportedTypes
(
importedTypes
);
interfaze
.
addMethod
(
mLogicalDeleteByPrimaryKey
);
...
...
@@ -229,7 +210,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
XmlElement
logicalDeleteByExample
=
new
XmlElement
(
"update"
);
//$NON-NLS-1$
logicalDeleteByExample
.
addAttribute
(
new
Attribute
(
"id"
,
METHOD_LOGICAL_DELETE_BY_EXAMPLE
));
logicalDeleteByExample
.
addAttribute
(
new
Attribute
(
"parameterType"
,
"map"
));
//$NON-NLS-1$ //$NON-NLS-2$
CommentTools
.
addComment
(
logicalDeleteByExample
);
commentGenerator
.
addComment
(
logicalDeleteByExample
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"update "
);
//$NON-NLS-1$
...
...
@@ -280,7 +261,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
}
}
logicalDeleteByPrimaryKey
.
addAttribute
(
new
Attribute
(
"parameterType"
,
parameterClass
));
CommentTools
.
addComment
(
logicalDeleteByPrimaryKey
);
commentGenerator
.
addComment
(
logicalDeleteByPrimaryKey
);
StringBuilder
sb1
=
new
StringBuilder
();
sb1
.
append
(
"update "
);
//$NON-NLS-1$
...
...
@@ -347,7 +328,8 @@ public class LogicalDeletePlugin extends PluginAdapter {
ArrayList
<
Field
>
fields
=
(
ArrayList
<
Field
>)
topLevelClass
.
getFields
();
// TODO 过期的
Field
field2
=
JavaElementGeneratorTools
.
generateStaticFinalField
(
"DEL_FLAG"
,
this
.
logicalDeleteColumn
.
getFullyQualifiedJavaType
(),
DEL_FLAG_NAME
,
introspectedTable
);
Field
field2
=
JavaElementGeneratorTools
.
generateStaticFinalField
(
"DEL_FLAG"
,
this
.
logicalDeleteColumn
.
getFullyQualifiedJavaType
(),
DEL_FLAG_NAME
);
commentGenerator
.
addFieldComment
(
field2
,
introspectedTable
);
field2
.
addAnnotation
(
"@Deprecated"
);
// 常量插入到第一位
fields
.
add
(
0
,
field2
);
...
...
@@ -364,7 +346,8 @@ public class LogicalDeletePlugin extends PluginAdapter {
}
else
{
delFlagOnValue
=
this
.
logicalDeleteValue
;
}
Field
field
=
JavaElementGeneratorTools
.
generateStaticFinalField
(
DEL_FLAG_NAME
,
this
.
logicalDeleteColumn
.
getFullyQualifiedJavaType
(),
delFlagOnValue
,
introspectedTable
);
Field
field
=
JavaElementGeneratorTools
.
generateStaticFinalField
(
DEL_FLAG_NAME
,
this
.
logicalDeleteColumn
.
getFullyQualifiedJavaType
(),
delFlagOnValue
);
commentGenerator
.
addFieldComment
(
field
,
introspectedTable
);
// 常量插入到第一位
fields
.
add
(
0
,
field
);
logger
.
debug
(
"itfsw(逻辑删除插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加方法DEL_FLAG_OFF的常量。"
);
...
...
@@ -380,7 +363,8 @@ public class LogicalDeletePlugin extends PluginAdapter {
}
else
{
unDelFlagOnValue
=
this
.
logicalUnDeleteValue
;
}
Field
field1
=
JavaElementGeneratorTools
.
generateStaticFinalField
(
UN_DEL_FLAG_NAME
,
this
.
logicalDeleteColumn
.
getFullyQualifiedJavaType
(),
unDelFlagOnValue
,
introspectedTable
);
Field
field1
=
JavaElementGeneratorTools
.
generateStaticFinalField
(
UN_DEL_FLAG_NAME
,
this
.
logicalDeleteColumn
.
getFullyQualifiedJavaType
(),
unDelFlagOnValue
);
commentGenerator
.
addFieldComment
(
field1
,
introspectedTable
);
// 常量插入到第一位
fields
.
add
(
0
,
field1
);
logger
.
debug
(
"itfsw(逻辑删除插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加方法DEL_FLAG_ON的常量。"
);
...
...
@@ -408,7 +392,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
if
(
"Criteria"
.
equals
(
innerClass
.
getType
().
getShortName
()))
{
// 增加逻辑删除条件
Method
method
=
new
Method
(
METHOD_LOGICAL_DELETE
);
CommentTools
.
add
MethodComment
(
method
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
method
,
introspectedTable
);
method
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
method
.
setReturnType
(
innerClass
.
getType
());
method
.
addParameter
(
new
Parameter
(
FullyQualifiedJavaType
.
getBooleanPrimitiveInstance
(),
"deleted"
));
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
View file @
6a153b23
...
...
@@ -16,15 +16,12 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.internal.util.JavaBeansUtil
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
...
...
@@ -36,22 +33,8 @@ import java.util.List;
* @time:2016/12/28 14:56
* ---------------------------------------------------------------------------
*/
public
class
ModelBuilderPlugin
extends
PluginAdapter
{
public
class
ModelBuilderPlugin
extends
BasePlugin
{
public
static
final
String
BUILDER_CLASS_NAME
=
"Builder"
;
// Builder 类名
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ModelBuilderPlugin
.
class
);
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
){
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
return
true
;
}
/**
* Model Methods 生成
...
...
@@ -69,13 +52,12 @@ public class ModelBuilderPlugin extends PluginAdapter {
InnerClass
innerClass
=
new
InnerClass
(
BUILDER_CLASS_NAME
);
innerClass
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
innerClass
.
setStatic
(
true
);
CommentTools
.
addInner
ClassComment
(
innerClass
,
introspectedTable
);
commentGenerator
.
add
ClassComment
(
innerClass
,
introspectedTable
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加内部Builder类。"
);
// 构建内部obj变量
Field
f
=
new
Field
(
"obj"
,
topLevelClass
.
getType
());
f
.
setVisibility
(
JavaVisibility
.
PRIVATE
);
CommentTools
.
addFieldComment
(
f
,
introspectedTable
);
Field
f
=
JavaElementGeneratorTools
.
generateField
(
"obj"
,
JavaVisibility
.
PRIVATE
,
topLevelClass
.
getType
(),
null
);
commentGenerator
.
addFieldComment
(
f
,
introspectedTable
);
innerClass
.
addField
(
f
);
// 构造构造方法
...
...
@@ -83,7 +65,7 @@ public class ModelBuilderPlugin extends PluginAdapter {
constructor
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
constructor
.
setConstructor
(
true
);
constructor
.
addBodyLine
(
new
StringBuilder
(
"this.obj = new "
).
append
(
topLevelClass
.
getType
().
getShortName
()).
append
(
"();"
).
toString
());
CommentTools
.
add
MethodComment
(
constructor
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
constructor
,
introspectedTable
);
innerClass
.
addMethod
(
constructor
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()+
".Builder增加的构造方法。"
);
...
...
@@ -93,14 +75,18 @@ public class ModelBuilderPlugin extends PluginAdapter {
Field
field
=
JavaBeansUtil
.
getJavaBeansField
(
introspectedColumn
,
context
,
introspectedTable
);
Method
setterMethod
=
JavaBeansUtil
.
getJavaBeansSetter
(
introspectedColumn
,
context
,
introspectedTable
);
Method
method
=
new
Method
(
field
.
getName
());
method
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
method
.
setReturnType
(
innerClass
.
getType
());
method
.
addParameter
(
new
Parameter
(
field
.
getType
(),
field
.
getName
()));
method
.
addBodyLine
(
new
StringBuilder
().
append
(
"obj."
).
append
(
setterMethod
.
getName
())
.
append
(
"("
).
append
(
field
.
getName
()).
append
(
");"
).
toString
());
method
.
addBodyLine
(
new
StringBuilder
().
append
(
"return this;"
).
toString
());
CommentTools
.
addMethodComment
(
method
,
introspectedTable
);
Method
method
=
JavaElementGeneratorTools
.
generateMethod
(
field
.
getName
(),
JavaVisibility
.
PUBLIC
,
innerClass
.
getType
(),
new
Parameter
(
field
.
getType
(),
field
.
getName
())
);
commentGenerator
.
addSetterComment
(
method
,
introspectedTable
,
introspectedColumn
);
method
=
JavaElementGeneratorTools
.
generateMethodBody
(
method
,
"obj."
+
setterMethod
.
getName
()
+
"("
+
field
.
getName
()
+
");"
,
"return this;"
);
innerClass
.
addMethod
(
method
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()+
".Builder增加"
+
method
.
getName
()+
"方法(复合主键)。"
);
}
...
...
@@ -111,23 +97,29 @@ public class ModelBuilderPlugin extends PluginAdapter {
if
(
field
.
isStatic
())
continue
;
Method
method
=
new
Method
(
field
.
getName
());
method
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
method
.
setReturnType
(
innerClass
.
getType
());
method
.
addParameter
(
new
Parameter
(
field
.
getType
(),
field
.
getName
()));
method
.
addBodyLine
(
new
StringBuilder
().
append
(
"obj."
).
append
(
field
.
getName
())
.
append
(
" = "
).
append
(
field
.
getName
()).
append
(
";"
).
toString
());
method
.
addBodyLine
(
new
StringBuilder
().
append
(
"return this;"
).
toString
());
CommentTools
.
addMethodComment
(
method
,
introspectedTable
);
Method
method
=
JavaElementGeneratorTools
.
generateMethod
(
field
.
getName
(),
JavaVisibility
.
PUBLIC
,
innerClass
.
getType
(),
new
Parameter
(
field
.
getType
(),
field
.
getName
())
);
commentGenerator
.
addGeneralMethodComment
(
method
,
introspectedTable
);
method
=
JavaElementGeneratorTools
.
generateMethodBody
(
method
,
"obj."
+
field
.
getName
()
+
" = "
+
field
.
getName
()
+
";"
,
"return this;"
);
innerClass
.
addMethod
(
method
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()+
".Builder增加"
+
method
.
getName
()+
"方法。"
);
}
Method
build
=
new
Method
(
"build"
);
build
.
setReturnType
(
topLevelClass
.
getType
());
build
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
Method
build
=
JavaElementGeneratorTools
.
generateMethod
(
"build"
,
JavaVisibility
.
PUBLIC
,
topLevelClass
.
getType
()
);
build
.
addBodyLine
(
"return this.obj;"
);
CommentTools
.
add
MethodComment
(
build
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
build
,
introspectedTable
);
innerClass
.
addMethod
(
build
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()+
".Builder增加build方法。"
);
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ModelColumnPlugin.java
View file @
6a153b23
...
...
@@ -16,15 +16,11 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.
CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.
BasePlugin
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.internal.util.JavaBeansUtil
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
...
...
@@ -36,22 +32,8 @@ import java.util.List;
* @time:2017/1/17 11:20
* ---------------------------------------------------------------------------
*/
public
class
ModelColumnPlugin
extends
PluginAdapter
{
public
class
ModelColumnPlugin
extends
BasePlugin
{
public
static
final
String
ENUM_NAME
=
"Column"
;
// 内部Enum名
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ModelColumnPlugin
.
class
);
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
return
true
;
}
/**
* Model Methods 生成
...
...
@@ -68,35 +50,35 @@ public class ModelColumnPlugin extends PluginAdapter {
InnerEnum
innerEnum
=
new
InnerEnum
(
new
FullyQualifiedJavaType
(
ENUM_NAME
));
innerEnum
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
innerEnum
.
setStatic
(
true
);
CommentTools
.
addInner
EnumComment
(
innerEnum
,
introspectedTable
);
commentGenerator
.
add
EnumComment
(
innerEnum
,
introspectedTable
);
logger
.
debug
(
"itfsw(数据Model属性对应Column获取插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加内部Builder类。"
);
// 生成属性和构造函数
Field
columnField
=
new
Field
(
"column"
,
FullyQualifiedJavaType
.
getStringInstance
());
columnField
.
setVisibility
(
JavaVisibility
.
PRIVATE
);
columnField
.
setFinal
(
true
);
CommentTools
.
addFieldComment
(
columnField
,
introspectedTable
);
commentGenerator
.
addFieldComment
(
columnField
,
introspectedTable
);
innerEnum
.
addField
(
columnField
);
Method
mValue
=
new
Method
(
"value"
);
mValue
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
mValue
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
mValue
.
addBodyLine
(
"return this.column;"
);
CommentTools
.
add
MethodComment
(
mValue
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
mValue
,
introspectedTable
);
innerEnum
.
addMethod
(
mValue
);
Method
mGetValue
=
new
Method
(
"getValue"
);
mGetValue
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
mGetValue
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
mGetValue
.
addBodyLine
(
"return this.column;"
);
CommentTools
.
add
MethodComment
(
mGetValue
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
mGetValue
,
introspectedTable
);
innerEnum
.
addMethod
(
mGetValue
);
Method
constructor
=
new
Method
(
ENUM_NAME
);
constructor
.
setConstructor
(
true
);
constructor
.
addBodyLine
(
"this.column = column;"
);
constructor
.
addParameter
(
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"column"
));
CommentTools
.
add
MethodComment
(
constructor
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
constructor
,
introspectedTable
);
innerEnum
.
addMethod
(
constructor
);
logger
.
debug
(
"itfsw(数据Model属性对应Column获取插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
".Column增加构造方法和column属性。"
);
...
...
@@ -119,14 +101,14 @@ public class ModelColumnPlugin extends PluginAdapter {
desc
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
desc
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
desc
.
addBodyLine
(
"return this.column + \" DESC\";"
);
CommentTools
.
add
MethodComment
(
desc
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
desc
,
introspectedTable
);
innerEnum
.
addMethod
(
desc
);
Method
asc
=
new
Method
(
"asc"
);
asc
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
asc
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
asc
.
addBodyLine
(
"return this.column + \" ASC\";"
);
CommentTools
.
add
MethodComment
(
asc
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
asc
,
introspectedTable
);
innerEnum
.
addMethod
(
asc
);
logger
.
debug
(
"itfsw(数据Model属性对应Column获取插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
".Column增加asc()和desc()方法。"
);
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
View file @
6a153b23
...
...
@@ -16,21 +16,15 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.
CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.
BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Document
;
import
org.mybatis.generator.api.dom.xml.TextElement
;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
import
static
org
.
mybatis
.
generator
.
internal
.
util
.
StringUtility
.
stringHasValue
;
...
...
@@ -42,22 +36,8 @@ import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
* @time:2016/12/28 14:56
* ---------------------------------------------------------------------------
*/
public
class
SelectOneByExamplePlugin
extends
PluginAdapter
{
public
class
SelectOneByExamplePlugin
extends
BasePlugin
{
public
static
final
String
METHOD_SELECT_ONE_BY_EXAMPLE
=
"selectOneByExample"
;
// 方法名
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SelectOneByExamplePlugin
.
class
);
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
){
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
return
true
;
}
/**
* Java Client Methods 生成
...
...
@@ -75,9 +55,9 @@ public class SelectOneByExamplePlugin extends PluginAdapter {
METHOD_SELECT_ONE_BY_EXAMPLE
,
JavaVisibility
.
DEFAULT
,
introspectedTable
.
getRules
().
calculateAllFieldsClass
(),
introspectedTable
,
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
)
);
commentGenerator
.
addGeneralMethodComment
(
method
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
method
);
...
...
@@ -101,7 +81,7 @@ public class SelectOneByExamplePlugin extends PluginAdapter {
// 生成查询语句
XmlElement
selectOneElement
=
new
XmlElement
(
"select"
);
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
selectOneElement
);
commentGenerator
.
addComment
(
selectOneElement
);
// 添加ID
selectOneElement
.
addAttribute
(
new
Attribute
(
"id"
,
METHOD_SELECT_ONE_BY_EXAMPLE
));
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
View file @
6a153b23
...
...
@@ -16,17 +16,13 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.
CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.
BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.PluginTools
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.*
;
import
org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -41,19 +37,13 @@ import java.util.regex.Pattern;
* @time:2017/4/20 15:39
* ---------------------------------------------------------------------------
*/
public
class
SelectiveEnhancedPlugin
extends
PluginAdapter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SelectiveEnhancedPlugin
.
class
);
public
class
SelectiveEnhancedPlugin
extends
BasePlugin
{
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
// 插件使用前提是使用了ModelColumnPlugin插件
if
(!
PluginTools
.
checkDependencyPlugin
(
ModelColumnPlugin
.
class
,
getContext
()))
{
...
...
@@ -66,7 +56,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"插件建议配置在所有插件末尾以便最后调用,否则某些Selective方法得不到增强!"
);
}
return
true
;
return
super
.
validate
(
warnings
)
;
}
/**
...
...
@@ -84,14 +74,14 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
// field
Field
selectiveColumnsField
=
new
Field
(
"selectiveColumns"
,
new
FullyQualifiedJavaType
(
"Map<String, Boolean>"
));
CommentTools
.
addFieldComment
(
selectiveColumnsField
,
introspectedTable
);
commentGenerator
.
addFieldComment
(
selectiveColumnsField
,
introspectedTable
);
selectiveColumnsField
.
setVisibility
(
JavaVisibility
.
PRIVATE
);
selectiveColumnsField
.
setInitializationString
(
"new HashMap<String, Boolean>()"
);
topLevelClass
.
addField
(
selectiveColumnsField
);
// Method isSelective
Method
mIsSelective
=
new
Method
(
"isSelective"
);
CommentTools
.
add
MethodComment
(
mIsSelective
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
mIsSelective
,
introspectedTable
);
mIsSelective
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
mIsSelective
.
setReturnType
(
FullyQualifiedJavaType
.
getBooleanPrimitiveInstance
());
mIsSelective
.
addBodyLine
(
"return this.selectiveColumns.size() > 0;"
);
...
...
@@ -99,7 +89,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
// Method isSelective
Method
mIsSelective1
=
new
Method
(
"isSelective"
);
CommentTools
.
add
MethodComment
(
mIsSelective1
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
mIsSelective1
,
introspectedTable
);
mIsSelective1
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
mIsSelective1
.
setReturnType
(
FullyQualifiedJavaType
.
getBooleanPrimitiveInstance
());
mIsSelective1
.
addParameter
(
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"column"
));
...
...
@@ -108,7 +98,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
// Method selective
Method
mSelective
=
new
Method
(
"selective"
);
CommentTools
.
add
MethodComment
(
mSelective
,
introspectedTable
);
commentGenerator
.
addGeneral
MethodComment
(
mSelective
,
introspectedTable
);
mSelective
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
mSelective
.
setReturnType
(
topLevelClass
.
getType
());
mSelective
.
addParameter
(
new
Parameter
(
new
FullyQualifiedJavaType
(
ModelColumnPlugin
.
ENUM_NAME
),
"columns"
,
true
));
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
View file @
6a153b23
...
...
@@ -16,11 +16,10 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.
CommentTools
;
import
com.itfsw.mybatis.generator.plugins.utils.
BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Document
;
...
...
@@ -28,8 +27,6 @@ import org.mybatis.generator.api.dom.xml.TextElement;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
org.mybatis.generator.codegen.mybatis3.ListUtilities
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
import
java.util.Properties
;
...
...
@@ -42,18 +39,12 @@ import java.util.Properties;
* @time:2017/3/21 10:59
* ---------------------------------------------------------------------------
*/
public
class
UpsertPlugin
extends
PluginAdapter
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BatchInsertPlugin
.
class
);
public
class
UpsertPlugin
extends
BasePlugin
{
public
static
final
String
METHOD_UPSERT
=
"upsert"
;
// 方法名
public
static
final
String
METHOD_UPSERT_SELECTIVE
=
"upsertSelective"
;
// 方法名
public
static
final
String
METHOD_UPSERT_BY_EXAMPLE
=
"upsertByExample"
;
// 方法名
public
static
final
String
METHOD_UPSERT_BY_EXAMPLE_SELECTIVE
=
"upsertByExampleSelective"
;
// 方法名
public
static
final
String
METHOD_BATCH_UPSERT
=
"batchUpsert"
;
// 方法名
public
static
final
String
METHOD_BATCH_UPSERT_SELECTIVE
=
"batchUpsertSelective"
;
// 方法名
public
static
final
String
METHOD_BATCH_UPSERT_BY_EXAMPLE
=
"batchUpsertByExample"
;
// 方法名
public
static
final
String
METHOD_BATCH_UPSERT_BY_EXAMPLE_SELECTIVE
=
"batchUpsertByExampleSelective"
;
// 方法名
public
static
final
String
PRE_ALLOW_MULTI_QUERIES
=
"allowMultiQueries"
;
// property allowMultiQueries
private
boolean
allowMultiQueries
=
false
;
// 是否允许多sql提交
...
...
@@ -62,11 +53,6 @@ public class UpsertPlugin extends PluginAdapter {
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
// 插件使用前提是数据库为MySQL
if
(
"com.mysql.jdbc.Driver"
.
equalsIgnoreCase
(
this
.
getContext
().
getJdbcConnectionConfiguration
().
getDriverClass
())
==
false
){
...
...
@@ -83,7 +69,7 @@ public class UpsertPlugin extends PluginAdapter {
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"插件您开启了allowMultiQueries支持,注意在jdbc url 配置中增加“allowMultiQueries=true”支持(不怎么建议使用该功能,开启多sql提交会增加sql注入的风险,请确保你所有sql都使用MyBatis书写,请不要使用statement进行sql提交)!"
);
}
return
true
;
return
super
.
validate
(
warnings
)
;
}
/**
...
...
@@ -102,9 +88,9 @@ public class UpsertPlugin extends PluginAdapter {
METHOD_UPSERT
,
JavaVisibility
.
DEFAULT
,
FullyQualifiedJavaType
.
getIntInstance
(),
introspectedTable
,
new
Parameter
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
(),
"record"
)
);
commentGenerator
.
addGeneralMethodComment
(
mUpsert
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsert
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsert方法。"
);
...
...
@@ -114,9 +100,9 @@ public class UpsertPlugin extends PluginAdapter {
METHOD_UPSERT_SELECTIVE
,
JavaVisibility
.
DEFAULT
,
FullyQualifiedJavaType
.
getIntInstance
(),
introspectedTable
,
new
Parameter
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
(),
"record"
)
);
commentGenerator
.
addGeneralMethodComment
(
mUpsertSelective
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsertSelective
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsertSelective方法。"
);
...
...
@@ -127,10 +113,10 @@ public class UpsertPlugin extends PluginAdapter {
METHOD_UPSERT_BY_EXAMPLE
,
JavaVisibility
.
DEFAULT
,
FullyQualifiedJavaType
.
getIntInstance
(),
introspectedTable
,
new
Parameter
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
(),
"record"
,
"@Param(\"record\")"
),
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
,
"@Param(\"example\")"
)
);
commentGenerator
.
addGeneralMethodComment
(
mUpsertByExample
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsertByExample
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsertByExample方法。"
);
...
...
@@ -140,10 +126,10 @@ public class UpsertPlugin extends PluginAdapter {
METHOD_UPSERT_BY_EXAMPLE_SELECTIVE
,
JavaVisibility
.
DEFAULT
,
FullyQualifiedJavaType
.
getIntInstance
(),
introspectedTable
,
new
Parameter
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
(),
"record"
,
"@Param(\"record\")"
),
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
,
"@Param(\"example\")"
)
);
commentGenerator
.
addGeneralMethodComment
(
mUpsertByExampleSelective
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsertByExampleSelective
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsertByExampleSelective方法。"
);
...
...
@@ -167,7 +153,7 @@ public class UpsertPlugin extends PluginAdapter {
XmlElement
eleUpsert
=
new
XmlElement
(
"insert"
);
eleUpsert
.
addAttribute
(
new
Attribute
(
"id"
,
METHOD_UPSERT
));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
eleUpsert
);
commentGenerator
.
addComment
(
eleUpsert
);
// 参数类型
eleUpsert
.
addAttribute
(
new
Attribute
(
"parameterType"
,
introspectedTable
.
getRules
().
calculateAllFieldsClass
().
getFullyQualifiedName
()));
...
...
@@ -190,7 +176,7 @@ public class UpsertPlugin extends PluginAdapter {
XmlElement
eleUpsertSelective
=
new
XmlElement
(
"insert"
);
eleUpsertSelective
.
addAttribute
(
new
Attribute
(
"id"
,
METHOD_UPSERT_SELECTIVE
));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
eleUpsertSelective
);
commentGenerator
.
addComment
(
eleUpsertSelective
);
// 参数类型
eleUpsertSelective
.
addAttribute
(
new
Attribute
(
"parameterType"
,
introspectedTable
.
getRules
().
calculateAllFieldsClass
().
getFullyQualifiedName
()));
...
...
@@ -216,7 +202,7 @@ public class UpsertPlugin extends PluginAdapter {
// 参数类型
eleUpsertByExample
.
addAttribute
(
new
Attribute
(
"parameterType"
,
"map"
));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
eleUpsertByExample
);
commentGenerator
.
addComment
(
eleUpsertByExample
);
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
XmlElementGeneratorTools
.
useGeneratedKeys
(
eleUpsertByExample
,
introspectedTable
,
"record."
);
...
...
@@ -245,7 +231,7 @@ public class UpsertPlugin extends PluginAdapter {
// 参数类型
eleUpsertByExampleSelective
.
addAttribute
(
new
Attribute
(
"parameterType"
,
"map"
));
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
CommentTools
.
addComment
(
eleUpsertByExampleSelective
);
commentGenerator
.
addComment
(
eleUpsertByExampleSelective
);
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
XmlElementGeneratorTools
.
useGeneratedKeys
(
eleUpsertByExampleSelective
,
introspectedTable
,
"record."
);
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/BasePlugin.java
0 → 100644
View file @
6a153b23
/*
* 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.utils.enhanced.IWCommentGenerator
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
/**
* ---------------------------------------------------------------------------
* 基础plugin
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2017/4/28 13:57
* ---------------------------------------------------------------------------
*/
public
class
BasePlugin
extends
PluginAdapter
{
protected
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BasePlugin
.
class
);
// 日志
protected
IWCommentGenerator
commentGenerator
=
new
IWCommentGenerator
();
// 注释工具
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 插件使用前提是targetRuntime为MyBatis3
if
(
StringUtility
.
stringHasValue
(
getContext
().
getTargetRuntime
())
&&
"MyBatis3"
.
equalsIgnoreCase
(
getContext
().
getTargetRuntime
())
==
false
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"要求运行targetRuntime必须为MyBatis3!"
);
return
false
;
}
return
true
;
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/CommentTools.java
deleted
100644 → 0
View file @
ce96a44f
/*
* 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
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
;
/**
* ---------------------------------------------------------------------------
* 插件评论生成工具
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2016/12/28 17:57
* ---------------------------------------------------------------------------
*/
public
class
CommentTools
{
/**
* 生成通用属性注解
*
* @param field
* @param introspectedTable
*/
public
static
void
addFieldComment
(
Field
field
,
IntrospectedTable
introspectedTable
)
{
StringBuilder
sb
=
new
StringBuilder
();
field
.
addJavaDocLine
(
"/**"
);
field
.
addJavaDocLine
(
" * 这是Mybatis Generator拓展插件生成的属性(请勿删除)."
);
sb
.
append
(
" * This field corresponds to the database table "
);
sb
.
append
(
introspectedTable
.
getFullyQualifiedTable
());
field
.
addJavaDocLine
(
sb
.
toString
());
field
.
addJavaDocLine
(
" *"
);
field
.
addJavaDocLine
(
" * "
+
MergeConstants
.
NEW_ELEMENT_TAG
);
field
.
addJavaDocLine
(
" * @project https://github.com/itfsw/mybatis-generator-plugin"
);
field
.
addJavaDocLine
(
" */"
);
}
/**
* 生成通用内部类注解
*
* @param innerClass 类
* @param introspectedTable 表
*/
public
static
void
addInnerClassComment
(
InnerClass
innerClass
,
IntrospectedTable
introspectedTable
)
{
StringBuilder
sb
=
new
StringBuilder
();
innerClass
.
addJavaDocLine
(
"/**"
);
innerClass
.
addJavaDocLine
(
" * 这是Mybatis Generator拓展插件生成的类(请勿删除)."
);
sb
.
append
(
" * This class corresponds to the database table "
);
sb
.
append
(
introspectedTable
.
getFullyQualifiedTable
());
innerClass
.
addJavaDocLine
(
sb
.
toString
());
innerClass
.
addJavaDocLine
(
" *"
);
innerClass
.
addJavaDocLine
(
" * "
+
MergeConstants
.
NEW_ELEMENT_TAG
);
innerClass
.
addJavaDocLine
(
" * @project https://github.com/itfsw/mybatis-generator-plugin"
);
innerClass
.
addJavaDocLine
(
" */"
);
}
/**
* 生成通用内部Enum注释
*
* @param innerEnum 类
* @param introspectedTable 表
*/
public
static
void
addInnerEnumComment
(
InnerEnum
innerEnum
,
IntrospectedTable
introspectedTable
)
{
StringBuilder
sb
=
new
StringBuilder
();
innerEnum
.
addJavaDocLine
(
"/**"
);
innerEnum
.
addJavaDocLine
(
" * 这是Mybatis Generator拓展插件生成的枚举(请勿删除)."
);
sb
.
append
(
" * This class corresponds to the database table "
);
sb
.
append
(
introspectedTable
.
getFullyQualifiedTable
());
innerEnum
.
addJavaDocLine
(
sb
.
toString
());
innerEnum
.
addJavaDocLine
(
" *"
);
innerEnum
.
addJavaDocLine
(
" * "
+
MergeConstants
.
NEW_ELEMENT_TAG
);
innerEnum
.
addJavaDocLine
(
" * @project https://github.com/itfsw/mybatis-generator-plugin"
);
innerEnum
.
addJavaDocLine
(
" */"
);
}
/**
* 生成通用方法注解
*
* @param method 方法
* @param introspectedTable 表
*/
public
static
void
addMethodComment
(
Method
method
,
IntrospectedTable
introspectedTable
)
{
StringBuilder
sb
=
new
StringBuilder
();
method
.
addJavaDocLine
(
"/**"
);
method
.
addJavaDocLine
(
" * 这是Mybatis Generator拓展插件生成的方法(请勿删除)."
);
sb
.
append
(
" * This method corresponds to the database table "
);
sb
.
append
(
introspectedTable
.
getFullyQualifiedTable
());
method
.
addJavaDocLine
(
sb
.
toString
());
method
.
addJavaDocLine
(
" *"
);
method
.
addJavaDocLine
(
" * "
+
MergeConstants
.
NEW_ELEMENT_TAG
);
method
.
addJavaDocLine
(
" * @project https://github.com/itfsw/mybatis-generator-plugin"
);
method
.
addJavaDocLine
(
" */"
);
}
/**
* 生成xml element 注释
*
* @param xmlElement the xml element
*/
public
static
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
(
" 这个节点为代码生成工具生成,请不要修改!"
));
xmlElement
.
addElement
(
new
TextElement
(
" @project https://github.com/itfsw/mybatis-generator-plugin"
));
xmlElement
.
addElement
(
new
TextElement
(
"-->"
));
}
/**
* 生成通用接口注解
*
* @param interf 接口
* @param introspectedTable 表
*/
public
static
void
addInterfaceComment
(
Interface
interf
,
IntrospectedTable
introspectedTable
)
{
StringBuilder
sb
=
new
StringBuilder
();
interf
.
addJavaDocLine
(
"/**"
);
interf
.
addJavaDocLine
(
" * 这是Mybatis Generator拓展插件生成的接口(请勿删除)."
);
sb
.
append
(
" * This class corresponds to the database table "
);
sb
.
append
(
introspectedTable
.
getFullyQualifiedTable
());
interf
.
addJavaDocLine
(
sb
.
toString
());
interf
.
addJavaDocLine
(
" *"
);
interf
.
addJavaDocLine
(
" * "
+
MergeConstants
.
NEW_ELEMENT_TAG
);
interf
.
addJavaDocLine
(
" * @project https://github.com/itfsw/mybatis-generator-plugin"
);
interf
.
addJavaDocLine
(
" */"
);
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/JavaElementGeneratorTools.java
View file @
6a153b23
...
...
@@ -16,7 +16,6 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.*
;
/**
...
...
@@ -35,12 +34,10 @@ public class JavaElementGeneratorTools {
* @param fieldName 常量名称
* @param javaType 类型
* @param initString 初始化字段
* @param introspectedTable 表
* @return
*/
public
static
Field
generateStaticFinalField
(
String
fieldName
,
FullyQualifiedJavaType
javaType
,
String
initString
,
IntrospectedTable
introspectedTable
){
public
static
Field
generateStaticFinalField
(
String
fieldName
,
FullyQualifiedJavaType
javaType
,
String
initString
){
Field
field
=
new
Field
(
fieldName
,
javaType
);
CommentTools
.
addFieldComment
(
field
,
introspectedTable
);
field
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
field
.
setStatic
(
true
);
field
.
setFinal
(
true
);
...
...
@@ -57,12 +54,10 @@ public class JavaElementGeneratorTools {
* @param visibility 可见性
* @param javaType 类型
* @param initString 初始化字段
* @param introspectedTable 表
* @return
*/
public
static
Field
generateField
(
String
fieldName
,
JavaVisibility
visibility
,
FullyQualifiedJavaType
javaType
,
String
initString
,
IntrospectedTable
introspectedTable
){
public
static
Field
generateField
(
String
fieldName
,
JavaVisibility
visibility
,
FullyQualifiedJavaType
javaType
,
String
initString
){
Field
field
=
new
Field
(
fieldName
,
javaType
);
CommentTools
.
addFieldComment
(
field
,
introspectedTable
);
field
.
setVisibility
(
visibility
);
if
(
initString
!=
null
){
field
.
setInitializationString
(
initString
);
...
...
@@ -76,13 +71,11 @@ public class JavaElementGeneratorTools {
* @param methodName 方法名
* @param visibility 可见性
* @param returnType 返回值类型
* @param introspectedTable 表
* @param parameters 参数列表
* @return
*/
public
static
Method
generateMethod
(
String
methodName
,
JavaVisibility
visibility
,
FullyQualifiedJavaType
returnType
,
IntrospectedTable
introspectedTable
,
Parameter
...
parameters
){
public
static
Method
generateMethod
(
String
methodName
,
JavaVisibility
visibility
,
FullyQualifiedJavaType
returnType
,
Parameter
...
parameters
){
Method
method
=
new
Method
(
methodName
);
CommentTools
.
addMethodComment
(
method
,
introspectedTable
);
method
.
setVisibility
(
visibility
);
method
.
setReturnType
(
returnType
);
if
(
parameters
!=
null
){
...
...
@@ -114,15 +107,13 @@ public class JavaElementGeneratorTools {
* 生成Filed的Set方法
*
* @param field field
* @param introspectedTable 表
* @return
*/
public
static
Method
generateSetterMethod
(
Field
field
,
IntrospectedTable
introspectedTable
){
public
static
Method
generateSetterMethod
(
Field
field
){
Method
method
=
generateMethod
(
"set"
+
field
.
getName
().
substring
(
0
,
1
).
toUpperCase
()
+
field
.
getName
().
substring
(
1
),
JavaVisibility
.
PUBLIC
,
null
,
introspectedTable
,
new
Parameter
(
field
.
getType
(),
field
.
getName
())
);
return
generateMethodBody
(
method
,
"this."
+
field
.
getName
()
+
" = "
+
field
.
getName
()
+
";"
);
...
...
@@ -132,15 +123,13 @@ public class JavaElementGeneratorTools {
* 生成Filed的Get方法
*
* @param field field
* @param introspectedTable 表
* @return
*/
public
static
Method
generateGetterMethod
(
Field
field
,
IntrospectedTable
introspectedTable
){
public
static
Method
generateGetterMethod
(
Field
field
){
Method
method
=
generateMethod
(
"get"
+
field
.
getName
().
substring
(
0
,
1
).
toUpperCase
()
+
field
.
getName
().
substring
(
1
),
JavaVisibility
.
PUBLIC
,
field
.
getType
(),
introspectedTable
field
.
getType
()
);
return
generateMethodBody
(
method
,
"return this."
+
field
.
getName
()
+
";"
);
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/enhanced/IWCommentGenerator.java
0 → 100644
View file @
6a153b23
/*
* 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
(
" */"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment