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
192cf209
Commit
192cf209
authored
May 14, 2018
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix[issues#24]:在单独使用某些插件,Mapper接口没有import的问题;
parent
a50ef78c
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
220 additions
and
160 deletions
+220
-160
src/main/java/com/itfsw/mybatis/generator/plugins/BatchInsertPlugin.java
...om/itfsw/mybatis/generator/plugins/BatchInsertPlugin.java
+3
-6
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
...tfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
+6
-5
src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java
...com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java
+4
-4
src/main/java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
...java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
+19
-22
src/main/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePlugin.java
.../itfsw/mybatis/generator/plugins/LogicalDeletePlugin.java
+22
-22
src/main/java/com/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
...m/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
+5
-4
src/main/java/com/itfsw/mybatis/generator/plugins/ModelColumnPlugin.java
...om/itfsw/mybatis/generator/plugins/ModelColumnPlugin.java
+8
-7
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
...w/mybatis/generator/plugins/SelectOneByExamplePlugin.java
+108
-76
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
...ava/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
+7
-10
src/main/java/com/itfsw/mybatis/generator/plugins/utils/FormatTools.java
...om/itfsw/mybatis/generator/plugins/utils/FormatTools.java
+38
-4
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/BatchInsertPlugin.java
View file @
192cf209
...
...
@@ -16,10 +16,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
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
com.itfsw.mybatis.generator.plugins.utils.*
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.*
;
...
...
@@ -88,7 +85,7 @@ public class BatchInsertPlugin extends BasePlugin {
);
commentGenerator
.
addGeneralMethodComment
(
mBatchInsert
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mBatchInsert
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mBatchInsert
);
logger
.
debug
(
"itfsw(批量插入插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加batchInsert方法。"
);
// 2. batchInsertSelective
...
...
@@ -102,7 +99,7 @@ public class BatchInsertPlugin extends BasePlugin {
);
commentGenerator
.
addGeneralMethodComment
(
mBatchInsertSelective
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mBatchInsertSelective
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mBatchInsertSelective
);
logger
.
debug
(
"itfsw(批量插入插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加batchInsertSelective方法。"
);
return
true
;
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
View file @
192cf209
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.FormatTools
;
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
;
...
...
@@ -91,7 +92,7 @@ public class ExampleEnhancedPlugin extends BasePlugin {
exampleMethod
,
"return this.example;"
);
innerClass
.
addMethod
(
exampleMethod
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
exampleMethod
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"."
+
innerClass
.
getType
().
getShortName
()
+
"增加工厂方法example"
);
}
...
...
@@ -116,7 +117,7 @@ public class ExampleEnhancedPlugin extends BasePlugin {
new
Parameter
(
innerClass
.
getType
(),
"add"
)
);
commentGenerator
.
addGeneralMethodComment
(
addMethod
,
introspectedTable
);
criteriaAddInterface
.
addMethod
(
addMethod
);
FormatTools
.
addMethodWithBestPosition
(
criteriaAddInterface
,
addMethod
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"."
+
innerClass
.
getType
().
getShortName
()
+
"."
+
criteriaAddInterface
.
getType
().
getShortName
()
+
"增加方法add"
);
InnerClass
innerClassWrapper
=
new
InnerInterfaceWrapperToInnerClass
(
criteriaAddInterface
);
...
...
@@ -140,7 +141,7 @@ public class ExampleEnhancedPlugin extends BasePlugin {
"}"
,
"return this;"
);
innerClass
.
addMethod
(
andIfMethod
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
andIfMethod
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"."
+
innerClass
.
getType
().
getShortName
()
+
"增加方法andIf"
);
}
...
...
@@ -163,7 +164,7 @@ public class ExampleEnhancedPlugin extends BasePlugin {
"this.setOrderByClause(orderByClause);"
,
"return this;"
);
topLevelClass
.
addMethod
(
orderByMethod
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
orderByMethod
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加方法orderBy"
);
// 添加orderBy
...
...
@@ -187,7 +188,7 @@ public class ExampleEnhancedPlugin extends BasePlugin {
"return this;"
);
topLevelClass
.
addMethod
(
orderByMethod1
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
orderByMethod1
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加方法orderBy(String ... orderByClauses)"
);
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java
View file @
192cf209
...
...
@@ -177,11 +177,11 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
mInc
.
addBodyLine
(
"this.value = value;"
);
mInc
.
addParameter
(
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"value"
));
commentGenerator
.
addGeneralMethodComment
(
mInc
,
introspectedTable
);
eIncrements
.
addMethod
(
mInc
);
FormatTools
.
addMethodWithBestPosition
(
eIncrements
,
mInc
);
Method
mValue
=
JavaElementGeneratorTools
.
generateGetterMethod
(
fValue
);
commentGenerator
.
addGeneralMethodComment
(
mValue
,
introspectedTable
);
eIncrements
.
addMethod
(
mValue
);
FormatTools
.
addMethodWithBestPosition
(
eIncrements
,
mValue
);
builderClass
.
addInnerEnum
(
eIncrements
);
// 增加field
...
...
@@ -198,10 +198,10 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
// getter&setter
Method
mGetter
=
JavaElementGeneratorTools
.
generateGetterMethod
(
fIncrements
);
commentGenerator
.
addGetterComment
(
mGetter
,
introspectedTable
,
null
);
topLevelClass
.
addMethod
(
mGetter
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
mGetter
);
Method
mSetter
=
JavaElementGeneratorTools
.
generateSetterMethod
(
fIncrements
);
commentGenerator
.
addSetterComment
(
mSetter
,
introspectedTable
,
null
);
topLevelClass
.
addMethod
(
mSetter
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
mSetter
);
// 增加判断方法
Method
mHasIncsForColumn
=
JavaElementGeneratorTools
.
generateMethod
(
IncrementsPlugin
.
METHOD_INC_CHECK
,
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
View file @
192cf209
...
...
@@ -17,6 +17,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.FormatTools
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.*
;
...
...
@@ -41,8 +42,8 @@ public class LimitPlugin extends BasePlugin {
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 该插件只支持MYSQL
if
(
"com.mysql.jdbc.Driver"
.
equalsIgnoreCase
(
this
.
getContext
().
getJdbcConnectionConfiguration
().
getDriverClass
())
==
false
){
warnings
.
add
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()+
"只支持MySQL数据库!"
);
if
(
"com.mysql.jdbc.Driver"
.
equalsIgnoreCase
(
this
.
getContext
().
getJdbcConnectionConfiguration
().
getDriverClass
())
==
false
)
{
warnings
.
add
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"只支持MySQL数据库!"
);
return
false
;
}
return
super
.
validate
(
warnings
);
...
...
@@ -51,7 +52,6 @@ public class LimitPlugin extends BasePlugin {
/**
* ModelExample Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param topLevelClass
* @param introspectedTable
* @return
...
...
@@ -77,25 +77,25 @@ public class LimitPlugin extends BasePlugin {
);
commentGenerator
.
addFieldComment
(
rowsField
,
introspectedTable
);
topLevelClass
.
addField
(
rowsField
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加offset和rows字段"
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加offset和rows字段"
);
// 增加getter && setter 方法
Method
mSetOffset
=
JavaElementGeneratorTools
.
generateSetterMethod
(
offsetField
);
commentGenerator
.
addGeneralMethodComment
(
mSetOffset
,
introspectedTable
);
topLevelClass
.
addMethod
(
mSetOffset
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
mSetOffset
);
Method
mGetOffset
=
JavaElementGeneratorTools
.
generateGetterMethod
(
offsetField
);
commentGenerator
.
addGeneralMethodComment
(
mGetOffset
,
introspectedTable
);
topLevelClass
.
addMethod
(
mGetOffset
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
mGetOffset
);
Method
mSetRows
=
JavaElementGeneratorTools
.
generateSetterMethod
(
rowsField
);
commentGenerator
.
addGeneralMethodComment
(
mSetRows
,
introspectedTable
);
topLevelClass
.
addMethod
(
mSetRows
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
mSetRows
);
Method
mGetRows
=
JavaElementGeneratorTools
.
generateGetterMethod
(
rowsField
);
commentGenerator
.
addGeneralMethodComment
(
mGetRows
,
introspectedTable
);
topLevelClass
.
addMethod
(
mGetRows
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加offset和rows的getter和setter实现。"
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
mGetRows
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加offset和rows的getter和setter实现。"
);
// 提供几个快捷方法
Method
setLimit
=
JavaElementGeneratorTools
.
generateMethod
(
...
...
@@ -110,7 +110,7 @@ public class LimitPlugin extends BasePlugin {
"this.rows = rows;"
,
"return this;"
);
topLevelClass
.
addMethod
(
setLimit
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
setLimit
);
Method
setLimit2
=
JavaElementGeneratorTools
.
generateMethod
(
"limit"
,
...
...
@@ -126,8 +126,8 @@ public class LimitPlugin extends BasePlugin {
"this.rows = rows;"
,
"return this;"
);
topLevelClass
.
addMethod
(
setLimit2
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加limit方法。"
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
setLimit2
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加limit方法。"
);
Method
setPage
=
JavaElementGeneratorTools
.
generateMethod
(
"page"
,
...
...
@@ -143,16 +143,16 @@ public class LimitPlugin extends BasePlugin {
"this.rows = pageSize;"
,
"return this;"
);
topLevelClass
.
addMethod
(
setPage
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加page方法"
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
setPage
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加page方法"
);
// !!! clear 方法增加 offset 和 rows的清理
List
<
Method
>
methodList
=
topLevelClass
.
getMethods
();
for
(
Method
method
:
methodList
)
{
if
(
method
.
getName
().
equals
(
"clear"
)){
for
(
Method
method
:
methodList
)
{
if
(
method
.
getName
().
equals
(
"clear"
))
{
method
.
addBodyLine
(
"rows = null;"
);
method
.
addBodyLine
(
"offset = null;"
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"修改clear方法,增加rows和offset字段的清空"
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"修改clear方法,增加rows和offset字段的清空"
);
}
}
...
...
@@ -162,7 +162,6 @@ public class LimitPlugin extends BasePlugin {
/**
* SQL Map Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param element
* @param introspectedTable
* @return
...
...
@@ -176,7 +175,6 @@ public class LimitPlugin extends BasePlugin {
/**
* SQL Map Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param element
* @param introspectedTable
* @return
...
...
@@ -189,11 +187,10 @@ public class LimitPlugin extends BasePlugin {
/**
* 生成limit节点
*
* @param element
* @param introspectedTable
*/
public
void
generateLimitElement
(
XmlElement
element
,
IntrospectedTable
introspectedTable
){
public
void
generateLimitElement
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
XmlElement
ifLimitNotNullElement
=
new
XmlElement
(
"if"
);
ifLimitNotNullElement
.
addAttribute
(
new
Attribute
(
"test"
,
"rows != null"
));
...
...
@@ -209,6 +206,6 @@ public class LimitPlugin extends BasePlugin {
element
.
addElement
(
ifLimitNotNullElement
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()+
"selectByExample方法增加分页条件。"
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"selectByExample方法增加分页条件。"
);
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePlugin.java
View file @
192cf209
...
...
@@ -165,7 +165,7 @@ public class LogicalDeletePlugin extends BasePlugin {
// 添加方法说明
commentGenerator
.
addGeneralMethodComment
(
mLogicalDeleteByExample
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mLogicalDeleteByExample
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mLogicalDeleteByExample
);
logger
.
debug
(
"itfsw(逻辑删除插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加方法logicalDeleteByExample。"
);
// 2. 判断是否有主键,生成主键删除方法
...
...
@@ -229,7 +229,7 @@ public class LogicalDeletePlugin extends BasePlugin {
// interface 增加方法
interfaze
.
addImportedTypes
(
importedTypes
);
interfaze
.
addMethod
(
mLogicalDeleteByPrimaryKey
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mLogicalDeleteByPrimaryKey
);
logger
.
debug
(
"itfsw(逻辑删除插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加方法logicalDeleteByPrimaryKey。"
);
// 增强selectByPrimaryKey
...
...
@@ -436,18 +436,18 @@ public class LogicalDeletePlugin extends BasePlugin {
* @param topLevelClass
* @param introspectedTable
*/
private
void
generateModelMethodsAndFields
(
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
){
private
void
generateModelMethodsAndFields
(
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
)
{
if
(
this
.
logicalDeleteColumn
!=
null
)
{
// 常量和逻辑删除方法跟随 逻辑删除列走
boolean
flag
=
false
;
for
(
Field
field
:
topLevelClass
.
getFields
()){
if
(
this
.
logicalDeleteColumn
.
getJavaProperty
().
equals
(
field
.
getName
())){
for
(
Field
field
:
topLevelClass
.
getFields
())
{
if
(
this
.
logicalDeleteColumn
.
getJavaProperty
().
equals
(
field
.
getName
()))
{
flag
=
true
;
break
;
}
}
if
(
flag
){
if
(
flag
)
{
ArrayList
<
Field
>
fields
=
(
ArrayList
<
Field
>)
topLevelClass
.
getFields
();
// 添加删除标志位常量
...
...
@@ -505,7 +505,7 @@ public class LogicalDeletePlugin extends BasePlugin {
);
commentGenerator
.
addGeneralMethodComment
(
mAndLogicalDeleted
,
introspectedTable
);
Method
logicalDeleteSetter
=
JavaBeansUtil
.
getJavaBeansSetter
(
this
.
logicalDeleteColumn
,
context
,
introspectedTable
);
mAndLogicalDeleted
.
addBodyLine
(
logicalDeleteSetter
.
getName
()
+
"(deleted ? "
+
this
.
logicalDeleteConstName
+
" : "
+
this
.
logicalUnDeleteConstName
+
");"
);
mAndLogicalDeleted
.
addBodyLine
(
logicalDeleteSetter
.
getName
()
+
"(deleted ? "
+
this
.
logicalDeleteConstName
+
" : "
+
this
.
logicalUnDeleteConstName
+
");"
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
mAndLogicalDeleted
);
}
}
...
...
@@ -564,13 +564,13 @@ public class LogicalDeletePlugin extends BasePlugin {
method
.
addBodyLine
(
sb
.
toString
());
innerClass
.
addMethod
(
method
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
method
);
// TODO 过期方法
Method
mAndDeleted
=
new
Method
(
method
);
mAndDeleted
.
setName
(
"andDeleted"
);
mAndDeleted
.
addAnnotation
(
"@Deprecated"
);
innerClass
.
addMethod
(
mAndDeleted
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
mAndDeleted
);
logger
.
debug
(
"itfsw(逻辑删除插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"."
+
innerClass
.
getType
().
getShortName
()
+
"增加andDeleted方法。"
);
}
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
View file @
192cf209
...
...
@@ -17,6 +17,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.FormatTools
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.PluginTools
;
import
com.itfsw.mybatis.generator.plugins.utils.enhanced.InnerTypeFullyQualifiedJavaType
;
...
...
@@ -116,7 +117,7 @@ public class ModelBuilderPlugin extends BasePlugin {
commentGenerator
.
addGeneralMethodComment
(
builder
,
introspectedTable
);
builder
.
setStatic
(
true
);
builder
.
addBodyLine
(
"return new "
+
builderType
.
getShortName
()
+
"();"
);
topLevelClass
.
addMethod
(
builder
);
FormatTools
.
addMethodWithBestPosition
(
topLevelClass
,
builder
);
commentGenerator
.
addClassComment
(
innerClass
,
introspectedTable
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
"增加内部Builder类。"
);
...
...
@@ -132,7 +133,7 @@ public class ModelBuilderPlugin extends BasePlugin {
constructor
.
setConstructor
(
true
);
constructor
.
addBodyLine
(
new
StringBuilder
(
"this.obj = new "
).
append
(
topLevelClass
.
getType
().
getShortName
()).
append
(
"();"
).
toString
());
commentGenerator
.
addGeneralMethodComment
(
constructor
,
introspectedTable
);
innerClass
.
addMethod
(
constructor
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
constructor
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
".Builder增加的构造方法。"
);
for
(
IntrospectedColumn
introspectedColumn
:
columns
)
{
...
...
@@ -154,7 +155,7 @@ public class ModelBuilderPlugin extends BasePlugin {
// hook
if
(
PluginTools
.
getHook
(
IModelBuilderPluginHook
.
class
).
modelBuilderSetterMethodGenerated
(
method
,
topLevelClass
,
innerClass
,
introspectedColumn
,
introspectedTable
))
{
innerClass
.
addMethod
(
method
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
method
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
".Builder增加"
+
method
.
getName
()
+
"方法(复合主键)。"
);
}
}
...
...
@@ -166,7 +167,7 @@ public class ModelBuilderPlugin extends BasePlugin {
);
build
.
addBodyLine
(
"return this.obj;"
);
commentGenerator
.
addGeneralMethodComment
(
build
,
introspectedTable
);
innerClass
.
addMethod
(
build
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
build
);
logger
.
debug
(
"itfsw(数据Model链式构建插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
".Builder增加build方法。"
);
// hook
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ModelColumnPlugin.java
View file @
192cf209
...
...
@@ -17,6 +17,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.FormatTools
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
...
...
@@ -110,22 +111,22 @@ public class ModelColumnPlugin extends BasePlugin {
mValue
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
mValue
.
addBodyLine
(
"return this.column;"
);
commentGenerator
.
addGeneralMethodComment
(
mValue
,
introspectedTable
);
innerEnum
.
addMethod
(
mValue
);
FormatTools
.
addMethodWithBestPosition
(
innerEnum
,
mValue
);
Method
mGetValue
=
new
Method
(
"getValue"
);
mGetValue
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
mGetValue
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
mGetValue
.
addBodyLine
(
"return this.column;"
);
commentGenerator
.
addGeneralMethodComment
(
mGetValue
,
introspectedTable
);
innerEnum
.
addMethod
(
mGetValue
);
FormatTools
.
addMethodWithBestPosition
(
innerEnum
,
mGetValue
);
Method
mGetJavaProperty
=
JavaElementGeneratorTools
.
generateGetterMethod
(
javaPropertyField
);
commentGenerator
.
addGeneralMethodComment
(
mGetJavaProperty
,
introspectedTable
);
innerEnum
.
addMethod
(
mGetJavaProperty
);
FormatTools
.
addMethodWithBestPosition
(
innerEnum
,
mGetJavaProperty
);
Method
mGetJdbcType
=
JavaElementGeneratorTools
.
generateGetterMethod
(
jdbcTypeField
);
commentGenerator
.
addGeneralMethodComment
(
mGetJdbcType
,
introspectedTable
);
innerEnum
.
addMethod
(
mGetJdbcType
);
FormatTools
.
addMethodWithBestPosition
(
innerEnum
,
mGetJdbcType
);
Method
constructor
=
new
Method
(
ENUM_NAME
);
constructor
.
setConstructor
(
true
);
...
...
@@ -136,7 +137,7 @@ public class ModelColumnPlugin extends BasePlugin {
constructor
.
addParameter
(
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"javaProperty"
));
constructor
.
addParameter
(
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"jdbcType"
));
commentGenerator
.
addGeneralMethodComment
(
constructor
,
introspectedTable
);
innerEnum
.
addMethod
(
constructor
);
FormatTools
.
addMethodWithBestPosition
(
innerEnum
,
constructor
);
logger
.
debug
(
"itfsw(数据Model属性对应Column获取插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
".Column增加构造方法和column属性。"
);
// Enum枚举
...
...
@@ -163,14 +164,14 @@ public class ModelColumnPlugin extends BasePlugin {
desc
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
desc
.
addBodyLine
(
"return this.column + \" DESC\";"
);
commentGenerator
.
addGeneralMethodComment
(
desc
,
introspectedTable
);
innerEnum
.
addMethod
(
desc
);
FormatTools
.
addMethodWithBestPosition
(
innerEnum
,
desc
);
Method
asc
=
new
Method
(
"asc"
);
asc
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
asc
.
setReturnType
(
FullyQualifiedJavaType
.
getStringInstance
());
asc
.
addBodyLine
(
"return this.column + \" ASC\";"
);
commentGenerator
.
addGeneralMethodComment
(
asc
,
introspectedTable
);
innerEnum
.
addMethod
(
asc
);
FormatTools
.
addMethodWithBestPosition
(
innerEnum
,
asc
);
logger
.
debug
(
"itfsw(数据Model属性对应Column获取插件):"
+
topLevelClass
.
getType
().
getShortName
()
+
".Column增加asc()和desc()方法。"
);
return
innerEnum
;
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
View file @
192cf209
...
...
@@ -38,64 +38,73 @@ import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
public
class
SelectOneByExamplePlugin
extends
BasePlugin
{
public
static
final
String
METHOD_SELECT_ONE_BY_EXAMPLE
=
"selectOneByExample"
;
// 方法名
public
static
final
String
METHOD_SELECT_ONE_BY_EXAMPLE_WITH_BLOBS
=
"selectOneByExampleWithBLOBs"
;
// 方法名
private
XmlElement
selectOneByExampleEle
;
private
XmlElement
selectOneByExampleWithBLOBsEle
;
/**
* Java Client Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param method
* @param interfaze
* @param topLevelClass
* @param introspectedTable
* @return
*/
@Override
public
boolean
client
Generated
(
Interface
interfaze
,
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
)
{
public
boolean
client
SelectByExampleWithBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
// 方法生成 selectOneByExample
Method
m
ethod
=
JavaElementGeneratorTools
.
generateMethod
(
METHOD_SELECT_ONE_BY_EXAMPLE
,
Method
selectOneM
ethod
=
JavaElementGeneratorTools
.
generateMethod
(
METHOD_SELECT_ONE_BY_EXAMPLE
_WITH_BLOBS
,
JavaVisibility
.
DEFAULT
,
JavaElementGeneratorTools
.
getModelTypeWith
out
BLOBs
(
introspectedTable
),
JavaElementGeneratorTools
.
getModelTypeWithBLOBs
(
introspectedTable
),
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
)
);
commentGenerator
.
addGeneralMethodComment
(
m
ethod
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
selectOneM
ethod
,
introspectedTable
);
// hook
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWith
outBLOBsMethodGenerated
(
m
ethod
,
interfaze
,
introspectedTable
))
{
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWith
BLOBsMethodGenerated
(
selectOneM
ethod
,
interfaze
,
introspectedTable
))
{
// interface 增加方法
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
selectOneMethod
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
}
return
super
.
clientSelectByExampleWithBLOBsMethodGenerated
(
method
,
interfaze
,
introspectedTable
);
}
// 方法生成 selectOneByExampleWithBLOBs !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
if
(
introspectedTable
.
hasBLOBColumns
())
{
/**
* Java Client Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param method
* @param interfaze
* @param introspectedTable
* @return
*/
@Override
public
boolean
clientSelectByExampleWithoutBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
// 方法生成 selectOneByExample
Method
method1
=
JavaElementGeneratorTools
.
generateMethod
(
METHOD_SELECT_ONE_BY_EXAMPLE_WITH_BLOBS
,
Method
selectOneMethod
=
JavaElementGeneratorTools
.
generateMethod
(
METHOD_SELECT_ONE_BY_EXAMPLE
,
JavaVisibility
.
DEFAULT
,
JavaElementGeneratorTools
.
getModelTypeWith
BLOBs
(
introspectedTable
),
JavaElementGeneratorTools
.
getModelTypeWithout
BLOBs
(
introspectedTable
),
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
)
);
commentGenerator
.
addGeneralMethodComment
(
method1
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
selectOneMethod
,
introspectedTable
);
// hook
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWithBLOBsMethodGenerated
(
method1
,
interfaze
,
introspectedTable
))
{
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWithoutBLOBsMethodGenerated
(
selectOneMethod
,
interfaze
,
introspectedTable
))
{
// interface 增加方法
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method1
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
}
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
selectOneMethod
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
}
return
true
;
return
super
.
clientSelectByExampleWithoutBLOBsMethodGenerated
(
selectOneMethod
,
interfaze
,
introspectedTable
);
}
/**
* SQL Map Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param
docu
ment
* @param
ele
ment
* @param introspectedTable
* @return
*/
@Override
public
boolean
sqlMap
DocumentGenerated
(
Document
docu
ment
,
IntrospectedTable
introspectedTable
)
{
public
boolean
sqlMap
SelectByExampleWithoutBLOBsElementGenerated
(
XmlElement
ele
ment
,
IntrospectedTable
introspectedTable
)
{
// ------------------------------------ selectOneByExample ----------------------------------
// 生成查询语句
XmlElement
selectOneElement
=
new
XmlElement
(
"select"
);
...
...
@@ -132,17 +141,18 @@ public class SelectOneByExamplePlugin extends BasePlugin {
// 只查询一条
selectOneElement
.
addElement
(
new
TextElement
(
"limit 1"
));
// hook
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
sqlMapSelectOneByExampleWithoutBLOBsElementGenerated
(
document
,
selectOneElement
,
introspectedTable
))
{
// 添加到根节点
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
selectOneElement
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加selectOneByExample方法。"
);
this
.
selectOneByExampleEle
=
selectOneElement
;
return
super
.
sqlMapSelectByExampleWithoutBLOBsElementGenerated
(
element
,
introspectedTable
);
}
// ------------------------------------ selectOneByExampleWithBLOBs ----------------------------------
// !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
if
(
introspectedTable
.
hasBLOBColumns
())
{
/**
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param element
* @param introspectedTable
* @return
*/
@Override
public
boolean
sqlMapSelectByExampleWithBLOBsElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
// 生成查询语句
XmlElement
selectOneWithBLOBsElement
=
new
XmlElement
(
"select"
);
// 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
...
...
@@ -157,7 +167,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
// 添加查询SQL
selectOneWithBLOBsElement
.
addElement
(
new
TextElement
(
"select"
));
sb
.
setLength
(
0
);
StringBuilder
sb
=
new
StringBuilder
(
);
if
(
stringHasValue
(
introspectedTable
.
getSelectByExampleQueryId
()))
{
sb
.
append
(
'\''
);
sb
.
append
(
introspectedTable
.
getSelectByExampleQueryId
());
...
...
@@ -183,15 +193,37 @@ public class SelectOneByExamplePlugin extends BasePlugin {
// 只查询一条
selectOneWithBLOBsElement
.
addElement
(
new
TextElement
(
"limit 1"
));
this
.
selectOneByExampleWithBLOBsEle
=
selectOneWithBLOBsElement
;
return
super
.
sqlMapSelectByExampleWithBLOBsElementGenerated
(
element
,
introspectedTable
);
}
/**
* SQL Map Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param document
* @param introspectedTable
* @return
*/
@Override
public
boolean
sqlMapDocumentGenerated
(
Document
document
,
IntrospectedTable
introspectedTable
)
{
if
(
selectOneByExampleEle
!=
null
)
{
// hook
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
sqlMapSelectOneByExampleWithoutBLOBsElementGenerated
(
document
,
selectOneByExampleEle
,
introspectedTable
))
{
// 添加到根节点
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
selectOneByExampleEle
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加selectOneByExample方法。"
);
}
}
if
(
selectOneByExampleWithBLOBsEle
!=
null
)
{
// hook
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
sqlMapSelectOneByExampleWithBLOBsElementGenerated
(
document
,
selectOne
WithBLOBsElement
,
introspectedTable
))
{
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
sqlMapSelectOneByExampleWithBLOBsElementGenerated
(
document
,
selectOne
ByExampleWithBLOBsEle
,
introspectedTable
))
{
// 添加到根节点
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
selectOne
WithBLOBsElement
);
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
selectOne
ByExampleWithBLOBsEle
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
}
}
return
true
;
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
View file @
192cf209
...
...
@@ -16,10 +16,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
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
com.itfsw.mybatis.generator.plugins.utils.*
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.IUpsertPluginHook
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
...
...
@@ -96,7 +93,7 @@ public class UpsertPlugin extends BasePlugin {
);
commentGenerator
.
addGeneralMethodComment
(
mUpsert
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsert
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mUpsert
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsert方法。"
);
// ====================================== upsertWithBLOBs ======================================
...
...
@@ -110,7 +107,7 @@ public class UpsertPlugin extends BasePlugin {
);
commentGenerator
.
addGeneralMethodComment
(
mUpsertWithBLOBs
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsertWithBLOBs
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mUpsertWithBLOBs
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsert方法。"
);
}
...
...
@@ -127,7 +124,7 @@ public class UpsertPlugin extends BasePlugin {
// hook
if
(
PluginTools
.
getHook
(
IUpsertPluginHook
.
class
).
clientUpsertSelectiveMethodGenerated
(
mUpsertSelective
,
interfaze
,
introspectedTable
))
{
// interface 增加方法
interfaze
.
addMethod
(
mUpsertSelective
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mUpsertSelective
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsertSelective方法。"
);
}
...
...
@@ -142,7 +139,7 @@ public class UpsertPlugin extends BasePlugin {
);
commentGenerator
.
addGeneralMethodComment
(
mUpsertByExample
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsertByExample
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mUpsertByExample
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsertByExample方法。"
);
// ====================================== upsertByExampleWithBLOBs ======================================
...
...
@@ -157,7 +154,7 @@ public class UpsertPlugin extends BasePlugin {
);
commentGenerator
.
addGeneralMethodComment
(
mUpsertByExampleWithBLOBs
,
introspectedTable
);
// interface 增加方法
interfaze
.
addMethod
(
mUpsertByExampleWithBLOBs
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mUpsertByExampleWithBLOBs
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsertByExample方法。"
);
}
...
...
@@ -173,7 +170,7 @@ public class UpsertPlugin extends BasePlugin {
// hook
if
(
PluginTools
.
getHook
(
IUpsertPluginHook
.
class
).
clientUpsertByExampleSelectiveMethodGenerated
(
mUpsertByExampleSelective
,
interfaze
,
introspectedTable
))
{
// interface 增加方法
interfaze
.
addMethod
(
mUpsertByExampleSelective
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mUpsertByExampleSelective
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加upsertByExampleSelective方法。"
);
}
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/FormatTools.java
View file @
192cf209
...
...
@@ -16,12 +16,10 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
;
import
com.itfsw.mybatis.generator.plugins.ModelColumnPlugin
;
import
org.mybatis.generator.api.CommentGenerator
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.InnerClass
;
import
org.mybatis.generator.api.dom.java.Interface
;
import
org.mybatis.generator.api.dom.java.Method
;
import
org.mybatis.generator.api.dom.java.TopLevelClass
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Element
;
import
org.mybatis.generator.api.dom.xml.TextElement
;
...
...
@@ -29,6 +27,8 @@ import org.mybatis.generator.api.dom.xml.XmlElement;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.TreeSet
;
/**
* ---------------------------------------------------------------------------
...
...
@@ -54,9 +54,43 @@ public class FormatTools {
* @param method
*/
public
static
void
addMethodWithBestPosition
(
Interface
interfacz
,
Method
method
)
{
// import
Set
<
FullyQualifiedJavaType
>
importTypes
=
new
TreeSet
<>();
// 返回
if
(
method
.
getReturnType
()
!=
null
)
{
importTypes
.
add
(
method
.
getReturnType
());
importTypes
.
addAll
(
method
.
getReturnType
().
getTypeArguments
());
}
// 参数 比较特殊的是ModelColumn生成的Column
for
(
Parameter
parameter
:
method
.
getParameters
())
{
boolean
flag
=
true
;
for
(
String
annotation
:
parameter
.
getAnnotations
())
{
if
(
annotation
.
startsWith
(
"@Param"
))
{
importTypes
.
add
(
new
FullyQualifiedJavaType
(
"org.apache.ibatis.annotations.Param"
));
if
(
annotation
.
matches
(
".*selective.*"
)
&&
parameter
.
getType
().
getShortName
().
equals
(
ModelColumnPlugin
.
ENUM_NAME
))
{
flag
=
false
;
}
}
}
if
(
flag
)
{
importTypes
.
add
(
parameter
.
getType
());
importTypes
.
addAll
(
parameter
.
getType
().
getTypeArguments
());
}
}
interfacz
.
addImportedTypes
(
importTypes
);
addMethodWithBestPosition
(
method
,
interfacz
.
getMethods
());
}
/**
* 在最佳位置添加方法
* @param innerEnum
* @param method
*/
public
static
void
addMethodWithBestPosition
(
InnerEnum
innerEnum
,
Method
method
)
{
addMethodWithBestPosition
(
method
,
innerEnum
.
getMethods
());
}
/**
* 在最佳位置添加方法
* @param topLevelClass
...
...
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