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
ba044ccd
Commit
ba044ccd
authored
Apr 21, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加SelectiveEnhancedPlugin插件;
parent
07c78ddd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
7 deletions
+44
-7
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
...sw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
+42
-5
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
...ava/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
+2
-2
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
View file @
ba044ccd
...
...
@@ -18,10 +18,12 @@ package com.itfsw.mybatis.generator.plugins;
import
com.itfsw.mybatis.generator.plugins.utils.CommentTools
;
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
;
...
...
@@ -150,7 +152,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
if
(
"updateByExampleSelective"
.
equals
(
id
))
{
List
<
XmlElement
>
eles
=
this
.
findEle
(
xmlElement
,
"set"
);
for
(
XmlElement
ele
:
eles
)
{
this
.
replaceEle
(
ele
,
"
_parameter
."
);
this
.
replaceEle
(
ele
,
"
record
."
);
}
}
// ====================================== 3. updateByPrimaryKeySelective ======================================
...
...
@@ -170,12 +172,13 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
// ====================================== 5. upsertByExampleSelective ======================================
if
(
"upsertByExampleSelective"
.
equals
(
id
))
{
List
<
XmlElement
>
eles
=
this
.
findEle
(
xmlElement
,
"trim"
);
for
(
XmlElement
ele
:
eles
)
{
this
.
replaceEle
(
ele
,
"_parameter."
);
}
this
.
replaceEle
(
eles
.
get
(
0
),
"record."
);
// upsertByExampleSelective的第二个trim比较特殊,需另行处理
this
.
replaceEleForUpsertByExampleSelective
(
eles
.
get
(
1
),
"record."
,
introspectedTable
);
List
<
XmlElement
>
eles1
=
this
.
findEle
(
xmlElement
,
"set"
);
for
(
XmlElement
ele
:
eles1
)
{
this
.
replaceEle
(
ele
,
"
_parameter
."
);
this
.
replaceEle
(
ele
,
"
record
."
);
}
}
...
...
@@ -258,4 +261,38 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
element
.
getElements
().
clear
();
element
.
addElement
(
chooseEle
);
}
/**
* 替换节点upsertByExampleSelective if信息
* @param element
* @param prefix
* @param introspectedTable
*/
private
void
replaceEleForUpsertByExampleSelective
(
XmlElement
element
,
String
prefix
,
IntrospectedTable
introspectedTable
)
{
// choose
XmlElement
chooseEle
=
new
XmlElement
(
"choose"
);
// when
XmlElement
whenEle
=
new
XmlElement
(
"when"
);
whenEle
.
addAttribute
(
new
Attribute
(
"test"
,
prefix
+
"isSelective()"
));
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getAllColumns
())
{
XmlElement
eleIf
=
new
XmlElement
(
"if"
);
eleIf
.
addAttribute
(
new
Attribute
(
"test"
,
prefix
+
"isSelective(\'"
+
MyBatis3FormattingUtilities
.
getEscapedColumnName
(
introspectedColumn
)
+
"\')"
));
eleIf
.
addElement
(
new
TextElement
(
MyBatis3FormattingUtilities
.
getParameterClause
(
introspectedColumn
,
prefix
)
+
","
));
whenEle
.
addElement
(
eleIf
);
}
// otherwise
XmlElement
otherwiseEle
=
new
XmlElement
(
"otherwise"
);
for
(
Element
ele
:
element
.
getElements
())
{
otherwiseEle
.
addElement
(
ele
);
}
chooseEle
.
addElement
(
whenEle
);
chooseEle
.
addElement
(
otherwiseEle
);
// 清空原始节点,新增choose节点
element
.
getElements
().
clear
();
element
.
addElement
(
chooseEle
);
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
View file @
ba044ccd
...
...
@@ -119,7 +119,7 @@ public class UpsertPlugin extends PluginAdapter {
// ====================================== 3. upsertByExample ======================================
Method
mUpsertByExample
=
new
Method
(
METHOD_UPSERT_BY_EXAMPLE
);
// 返回值类型
mUpsertByExample
.
setReturnType
(
null
);
mUpsertByExample
.
setReturnType
(
FullyQualifiedJavaType
.
getIntInstance
()
);
// 添加参数
mUpsertByExample
.
addParameter
(
new
Parameter
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
(),
"record"
,
"@Param(\"record\")"
));
mUpsertByExample
.
addParameter
(
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
,
"@Param(\"example\")"
));
...
...
@@ -132,7 +132,7 @@ public class UpsertPlugin extends PluginAdapter {
// ====================================== 4. upsertByExampleSelective ======================================
Method
mUpsertByExampleSelective
=
new
Method
(
METHOD_UPSERT_BY_EXAMPLE_SELECTIVE
);
// 返回值类型
mUpsertByExampleSelective
.
setReturnType
(
null
);
mUpsertByExampleSelective
.
setReturnType
(
FullyQualifiedJavaType
.
getIntInstance
()
);
// 添加参数
mUpsertByExampleSelective
.
addParameter
(
new
Parameter
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
(),
"record"
,
"@Param(\"record\")"
));
mUpsertByExampleSelective
.
addParameter
(
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
,
"@Param(\"example\")"
));
...
...
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