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
09065650
Commit
09065650
authored
Apr 28, 2018
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构代码插件依赖关系
parent
c33616c4
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
73 deletions
+164
-73
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
...sw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
+26
-4
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
...ava/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
+2
-2
src/main/java/com/itfsw/mybatis/generator/plugins/utils/XmlElementGeneratorTools.java
...tis/generator/plugins/utils/XmlElementGeneratorTools.java
+136
-67
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
View file @
09065650
...
...
@@ -339,7 +339,17 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
*/
@Override
public
boolean
sqlMapUpsertByExampleSelectiveElementGenerated
(
XmlElement
element
,
List
<
IntrospectedColumn
>
columns
,
XmlElement
insertColumnsEle
,
XmlElement
insertValuesEle
,
XmlElement
setsEle
,
IntrospectedTable
introspectedTable
)
{
return
false
;
// 替换insert column
XmlElementGeneratorTools
.
replaceXmlElement
(
insertColumnsEle
,
this
.
generateInsertColumnSelective
(
columns
));
// 替换insert values
XmlElementGeneratorTools
.
replaceXmlElement
(
insertValuesEle
,
this
.
generateInsertValuesSelective
(
columns
,
false
));
// 替换update set
XmlElementGeneratorTools
.
replaceXmlElement
(
setsEle
,
this
.
generateSetsSelective
(
columns
));
return
true
;
}
// ====================================================== 一些私有节点生成方法 =========================================================
...
...
@@ -384,6 +394,16 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
* @return
*/
private
XmlElement
generateInsertValuesSelective
(
List
<
IntrospectedColumn
>
columns
)
{
return
generateInsertValuesSelective
(
columns
,
true
);
}
/**
* insert column selective
* @param columns
* @param bracket
* @return
*/
private
XmlElement
generateInsertValuesSelective
(
List
<
IntrospectedColumn
>
columns
,
boolean
bracket
)
{
XmlElement
insertValuesChooseEle
=
new
XmlElement
(
"choose"
);
XmlElement
valuesWhenEle
=
new
XmlElement
(
"when"
);
...
...
@@ -393,15 +413,17 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
XmlElement
valuesForeachEle
=
new
XmlElement
(
"foreach"
);
valuesForeachEle
.
addAttribute
(
new
Attribute
(
"collection"
,
"selective"
));
valuesForeachEle
.
addAttribute
(
new
Attribute
(
"item"
,
"column"
));
valuesForeachEle
.
addAttribute
(
new
Attribute
(
"open"
,
"("
));
valuesForeachEle
.
addAttribute
(
new
Attribute
(
"separator"
,
","
));
valuesForeachEle
.
addAttribute
(
new
Attribute
(
"close"
,
")"
));
if
(
bracket
)
{
valuesForeachEle
.
addAttribute
(
new
Attribute
(
"open"
,
"("
));
valuesForeachEle
.
addAttribute
(
new
Attribute
(
"close"
,
")"
));
}
valuesForeachEle
.
addElement
(
new
TextElement
(
"#{record.${column.javaProperty},jdbcType=${column.jdbcType}}"
));
valuesWhenEle
.
addElement
(
valuesForeachEle
);
XmlElement
valuesOtherwiseEle
=
new
XmlElement
(
"otherwise"
);
insertValuesChooseEle
.
addElement
(
valuesOtherwiseEle
);
valuesOtherwiseEle
.
addElement
(
XmlElementGeneratorTools
.
generateValuesSelective
(
columns
,
"record."
));
valuesOtherwiseEle
.
addElement
(
XmlElementGeneratorTools
.
generateValuesSelective
(
columns
,
"record."
,
bracket
));
return
insertValuesChooseEle
;
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
View file @
09065650
...
...
@@ -217,7 +217,7 @@ public class UpsertPlugin extends BasePlugin {
insertEle
.
addAttribute
(
new
Attribute
(
"parameterType"
,
introspectedTable
.
getRules
().
calculateAllFieldsClass
().
getFullyQualifiedName
()));
// 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
XmlElementGeneratorTools
.
useGeneratedKeys
(
insertEle
,
introspectedTable
);
XmlElementGeneratorTools
.
useGeneratedKeys
(
insertEle
,
introspectedTable
,
"record."
);
// insert
insertEle
.
addElement
(
new
TextElement
(
"insert into "
+
introspectedTable
.
getFullyQualifiedTableNameAtRuntime
()));
...
...
@@ -349,7 +349,7 @@ public class UpsertPlugin extends BasePlugin {
// insert
updateEle
.
addElement
(
new
TextElement
(
"insert into "
+
introspectedTable
.
getFullyQualifiedTableNameAtRuntime
()));
for
(
Element
element
:
XmlElementGeneratorTools
.
generateKeys
(
columns
))
{
for
(
Element
element
:
XmlElementGeneratorTools
.
generateKeys
(
columns
,
"record."
))
{
updateEle
.
addElement
(
element
);
}
this
.
generateExistsClause
(
introspectedTable
,
updateEle
,
XmlElementGeneratorTools
.
generateValues
(
columns
,
"record."
,
false
));
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/XmlElementGeneratorTools.java
View file @
09065650
This diff is collapsed.
Click to expand it.
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