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
02e0367d
Commit
02e0367d
authored
Jul 03, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新插件SelectSelectivePlugin实现
parent
7b081648
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
425 additions
and
21 deletions
+425
-21
src/main/java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
...java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
+25
-15
src/main/java/com/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
...m/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
+2
-2
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
...w/mybatis/generator/plugins/SelectOneByExamplePlugin.java
+5
-4
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
...tfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
+239
-0
src/main/java/com/itfsw/mybatis/generator/plugins/utils/FormatTools.java
...om/itfsw/mybatis/generator/plugins/utils/FormatTools.java
+154
-0
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/LimitPlugin.java
View file @
02e0367d
...
@@ -169,6 +169,31 @@ public class LimitPlugin extends BasePlugin {
...
@@ -169,6 +169,31 @@ public class LimitPlugin extends BasePlugin {
*/
*/
@Override
@Override
public
boolean
sqlMapSelectByExampleWithoutBLOBsElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
public
boolean
sqlMapSelectByExampleWithoutBLOBsElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
this
.
generateLimitElement
(
element
,
introspectedTable
);
return
true
;
}
/**
* SQL Map Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param element
* @param introspectedTable
* @return
*/
@Override
public
boolean
sqlMapSelectByExampleWithBLOBsElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
this
.
generateLimitElement
(
element
,
introspectedTable
);
return
true
;
}
/**
* 生成limit节点
*
* @param element
* @param introspectedTable
*/
public
void
generateLimitElement
(
XmlElement
element
,
IntrospectedTable
introspectedTable
){
XmlElement
ifLimitNotNullElement
=
new
XmlElement
(
"if"
);
XmlElement
ifLimitNotNullElement
=
new
XmlElement
(
"if"
);
ifLimitNotNullElement
.
addAttribute
(
new
Attribute
(
"test"
,
"rows != null"
));
ifLimitNotNullElement
.
addAttribute
(
new
Attribute
(
"test"
,
"rows != null"
));
...
@@ -185,20 +210,5 @@ public class LimitPlugin extends BasePlugin {
...
@@ -185,20 +210,5 @@ public class LimitPlugin extends BasePlugin {
element
.
addElement
(
ifLimitNotNullElement
);
element
.
addElement
(
ifLimitNotNullElement
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()+
"selectByExample方法增加分页条件。"
);
logger
.
debug
(
"itfsw(MySQL分页插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()+
"selectByExample方法增加分页条件。"
);
return
true
;
}
/**
* SQL Map Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param element
* @param introspectedTable
* @return
*/
@Override
public
boolean
sqlMapSelectByExampleWithBLOBsElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
return
this
.
sqlMapSelectByExampleWithoutBLOBsElementGenerated
(
element
,
introspectedTable
);
}
}
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/ModelBuilderPlugin.java
View file @
02e0367d
...
@@ -17,9 +17,9 @@
...
@@ -17,9 +17,9 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.FormatTools
;
import
com.itfsw.mybatis.generator.plugins.utils.IncrementsPluginTools
;
import
com.itfsw.mybatis.generator.plugins.utils.IncrementsPluginTools
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.enhanced.JavaElementEnhanced
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.java.*
;
...
@@ -200,7 +200,7 @@ public class ModelBuilderPlugin extends BasePlugin {
...
@@ -200,7 +200,7 @@ public class ModelBuilderPlugin extends BasePlugin {
mIncrements
.
addBodyLine
(
"obj."
+
setterMethod
.
getName
()
+
"("
+
field
.
getName
()
+
");"
);
mIncrements
.
addBodyLine
(
"obj."
+
setterMethod
.
getName
()
+
"("
+
field
.
getName
()
+
");"
);
mIncrements
.
addBodyLine
(
"return this;"
);
mIncrements
.
addBodyLine
(
"return this;"
);
JavaElementEnhanced
.
addMethodWithBestPosition
(
innerClass
,
mIncrements
);
FormatTools
.
addMethodWithBestPosition
(
innerClass
,
mIncrements
);
}
}
}
}
}
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
View file @
02e0367d
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
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.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedColumn
;
...
@@ -132,7 +133,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -132,7 +133,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
commentGenerator
.
addGeneralMethodComment
(
method
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
method
,
introspectedTable
);
// interface 增加方法
// interface 增加方法
interfaze
.
addMethod
(
method
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
// 方法生成 selectOneByExampleWithBLOBs !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
// 方法生成 selectOneByExampleWithBLOBs !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
...
@@ -147,7 +148,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -147,7 +148,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
commentGenerator
.
addGeneralMethodComment
(
method1
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
method1
,
introspectedTable
);
// interface 增加方法
// interface 增加方法
interfaze
.
addMethod
(
method1
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method1
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
}
}
...
@@ -200,7 +201,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -200,7 +201,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
// 只查询一条
// 只查询一条
selectOneElement
.
addElement
(
new
TextElement
(
"limit 1"
));
selectOneElement
.
addElement
(
new
TextElement
(
"limit 1"
));
// 添加到根节点
// 添加到根节点
document
.
getRootElement
().
addElement
(
selectOneElement
);
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
selectOneElement
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加selectOneByExample方法。"
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加selectOneByExample方法。"
);
// ------------------------------------ selectOneByExampleWithBLOBs ----------------------------------
// ------------------------------------ selectOneByExampleWithBLOBs ----------------------------------
...
@@ -247,7 +248,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -247,7 +248,7 @@ public class SelectOneByExamplePlugin extends BasePlugin {
selectOneWithBLOBsElement
.
addElement
(
new
TextElement
(
"limit 1"
));
selectOneWithBLOBsElement
.
addElement
(
new
TextElement
(
"limit 1"
));
// 添加到根节点
// 添加到根节点
document
.
getRootElement
().
addElement
(
selectOneWithBLOBsElement
);
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
selectOneWithBLOBsElement
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
}
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
0 → 100644
View file @
02e0367d
This diff is collapsed.
Click to expand it.
src/main/java/com/itfsw/mybatis/generator/plugins/utils/
enhanced/JavaElementEnhanced
.java
→
src/main/java/com/itfsw/mybatis/generator/plugins/utils/
FormatTools
.java
View file @
02e0367d
...
@@ -14,22 +14,26 @@
...
@@ -14,22 +14,26 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
.
enhanced
;
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
;
import
org.mybatis.generator.api.dom.java.InnerClass
;
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.Method
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Element
;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
java.util.List
;
import
java.util.List
;
/**
/**
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
*
JavaElement 增强
*
格式化工具,优化输出
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
* @author: hewei
* @author: hewei
* @time:2017/6/
19 16:34
* @time:2017/6/
30 10:53
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
*/
*/
public
class
JavaElementEnhanced
{
public
class
FormatTools
{
/**
/**
* 在最佳位置添加方法
* 在最佳位置添加方法
*
*
...
@@ -42,16 +46,109 @@ public class JavaElementEnhanced {
...
@@ -42,16 +46,109 @@ public class JavaElementEnhanced {
for
(
int
i
=
0
;
i
<
methods
.
size
();
i
++){
for
(
int
i
=
0
;
i
<
methods
.
size
();
i
++){
Method
m
=
methods
.
get
(
i
);
Method
m
=
methods
.
get
(
i
);
if
(
m
.
getName
().
equals
(
method
.
getName
())){
if
(
m
.
getName
().
equals
(
method
.
getName
())){
if
(
m
.
getParameters
().
size
()
<=
method
.
getParameters
().
size
()
||
index
==
-
1
){
if
(
m
.
getParameters
().
size
()
<=
method
.
getParameters
().
size
()){
index
=
i
+
1
;
}
else
{
index
=
i
;
index
=
i
;
}
}
}
else
if
(
m
.
getName
().
startsWith
(
method
.
getName
())){
if
(
index
==
-
1
){
index
=
i
;
}
}
else
if
(
method
.
getName
().
startsWith
(
m
.
getName
())){
index
=
i
+
1
;
}
}
}
}
if
(
index
==
-
1
){
if
(
index
==
-
1
||
index
>=
methods
.
size
()
){
innerClass
.
addMethod
(
method
);
innerClass
.
addMethod
(
method
);
}
else
{
}
else
{
methods
.
add
(
index
,
method
);
methods
.
add
(
index
,
method
);
}
}
}
}
/**
* 在最佳位置添加方法
*
* @param interfacz
* @param method
*/
public
static
void
addMethodWithBestPosition
(
Interface
interfacz
,
Method
method
){
List
<
Method
>
methods
=
interfacz
.
getMethods
();
int
index
=
-
1
;
for
(
int
i
=
0
;
i
<
methods
.
size
();
i
++){
Method
m
=
methods
.
get
(
i
);
if
(
m
.
getName
().
equals
(
method
.
getName
())){
if
(
m
.
getParameters
().
size
()
<=
method
.
getParameters
().
size
()){
index
=
i
+
1
;
}
else
{
index
=
i
;
}
}
else
if
(
m
.
getName
().
startsWith
(
method
.
getName
())){
if
(
index
==
-
1
){
index
=
i
;
}
}
else
if
(
method
.
getName
().
startsWith
(
m
.
getName
())){
index
=
i
+
1
;
}
}
if
(
index
==
-
1
||
index
>=
methods
.
size
()){
interfacz
.
addMethod
(
method
);
}
else
{
methods
.
add
(
index
,
method
);
}
}
/**
* 在最佳位置添加节点
*
* @param rootElement
* @param element
*/
public
static
void
addElementWithBestPosition
(
XmlElement
rootElement
,
XmlElement
element
){
String
id
=
getIdFromElement
(
element
);
if
(
id
==
null
){
rootElement
.
addElement
(
element
);
}
else
{
List
<
Element
>
elements
=
rootElement
.
getElements
();
int
index
=
-
1
;
for
(
int
i
=
0
;
i
<
elements
.
size
();
i
++){
Element
ele
=
elements
.
get
(
i
);
if
(
ele
instanceof
XmlElement
){
String
eleId
=
getIdFromElement
((
XmlElement
)
ele
);
if
(
eleId
!=
null
){
if
(
eleId
.
startsWith
(
id
)){
if
(
index
==
-
1
){
index
=
i
;
}
}
else
if
(
id
.
startsWith
(
eleId
)){
index
=
i
+
1
;
}
}
}
}
if
(
index
==
-
1
||
index
>=
elements
.
size
()){
rootElement
.
addElement
(
element
);
}
else
{
elements
.
add
(
index
,
element
);
}
}
}
/**
* 找出节点ID值
*
* @param element
* @return
*/
private
static
String
getIdFromElement
(
XmlElement
element
){
for
(
Attribute
attribute
:
element
.
getAttributes
()){
if
(
attribute
.
getName
().
equals
(
"id"
)){
return
attribute
.
getValue
();
}
}
return
null
;
}
}
}
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