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
38417972
Commit
38417972
authored
Jan 16, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ExampleEnhancedPlugin 插件增加OrderBy方法
parent
ce099f81
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
10 deletions
+37
-10
README.md
README.md
+6
-5
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
...tfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
+31
-5
No files found.
README.md
View file @
38417972
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
查询单条数据插件(SelectOneByExamplePlugin)
*
查询单条数据插件(SelectOneByExamplePlugin)
*
MySQL分页插件(LimitPlugin)
*
MySQL分页插件(LimitPlugin)
*
数据Model链式构建插件(ModelBuilderPlugin)
*
数据Model链式构建插件(ModelBuilderPlugin)
*
Example Criteria 增强插件(
CriteriaBuilderPlugin
)
*
Example Criteria 增强插件(
ExampleEnhancedPlugin(CriteriaBuilderPlugin这个是老版本叫法,已经弃用)
)
*
Example 目标包修改插件(ExampleTargetPlugin)
*
Example 目标包修改插件(ExampleTargetPlugin)
*
批量插入插件(BatchInsertPlugin)
*
批量插入插件(BatchInsertPlugin)
*
逻辑删除插件(LogicalDeletePlugin)
*
逻辑删除插件(LogicalDeletePlugin)
...
@@ -146,13 +146,14 @@ public class Test {
...
@@ -146,13 +146,14 @@ public class Test {
}
}
}
}
```
```
### 4. Example Criteria 增强插件(example,andIf)
### 4. Example 增强插件(example,andIf)
*
表Example增加Criteria的快速返回example()方法。
*
Criteria的快速返回example()方法。
*
Criteria链式调用增强,以前如果有按条件增加的查询语句会打乱链式查询构建,现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。
*
Criteria链式调用增强,以前如果有按条件增加的查询语句会打乱链式查询构建,现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。
*
Example增强了setOrderByClause方法,新增orderBy(String orderByClause)方法直接返回example,增强链式调用,可以一路.下去了。
插件:
插件:
```
xml
```
xml
<!-- Example Criteria 增强插件 -->
<!-- Example Criteria 增强插件 -->
<plugin
type=
"com.itfsw.mybatis.generator.plugins.
CriteriaBuilder
Plugin"
/>
<plugin
type=
"com.itfsw.mybatis.generator.plugins.
ExampleEnhanced
Plugin"
/>
```
```
使用:
使用:
```
java
```
java
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleEnhancedPlugin.java
View file @
38417972
...
@@ -60,8 +60,12 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
...
@@ -60,8 +60,12 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
if
(!
"createCriteriaInternal"
.
equals
(
method
.
getName
()))
if
(!
"createCriteriaInternal"
.
equals
(
method
.
getName
()))
continue
;
continue
;
method
.
getBodyLines
().
set
(
0
,
"Criteria criteria = new Criteria(this);"
);
method
.
getBodyLines
().
set
(
0
,
"Criteria criteria = new Criteria(this);"
);
logger
.
debug
(
"itfsw
:CriteriaBuilder修改Example的
createCriteriaInternal方法,修改构造Criteria时传入Example对象"
);
logger
.
debug
(
"itfsw
(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"修改
createCriteriaInternal方法,修改构造Criteria时传入Example对象"
);
}
}
// orderBy方法
addOrderByMethodToExample
(
topLevelClass
,
introspectedTable
);
return
true
;
return
true
;
}
}
...
@@ -83,7 +87,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
...
@@ -83,7 +87,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
if
(
method
.
isConstructor
())
{
if
(
method
.
isConstructor
())
{
method
.
addParameter
(
new
Parameter
(
topLevelClass
.
getType
(),
"example"
));
method
.
addParameter
(
new
Parameter
(
topLevelClass
.
getType
(),
"example"
));
method
.
addBodyLine
(
"this.example = example;"
);
method
.
addBodyLine
(
"this.example = example;"
);
logger
.
debug
(
"itfsw
:CriteriaBuilder修改Criteria的
构造方法,增加example参数"
);
logger
.
debug
(
"itfsw
(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"修改
构造方法,增加example参数"
);
}
}
}
}
...
@@ -94,7 +98,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
...
@@ -94,7 +98,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
method
.
addBodyLine
(
"return this.example;"
);
method
.
addBodyLine
(
"return this.example;"
);
CommentTools
.
addGeneralMethodComment
(
method
,
introspectedTable
);
CommentTools
.
addGeneralMethodComment
(
method
,
introspectedTable
);
innerClass
.
addMethod
(
method
);
innerClass
.
addMethod
(
method
);
logger
.
debug
(
"itfsw
:CriteriaBuilder
增加工厂方法example"
);
logger
.
debug
(
"itfsw
(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"."
+
innerClass
.
getType
().
getShortName
()+
"
增加工厂方法example"
);
}
}
...
@@ -110,6 +114,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
...
@@ -110,6 +114,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
InnerInterface
criteriaAddInterface
=
new
InnerInterface
(
"ICriteriaAdd"
);
InnerInterface
criteriaAddInterface
=
new
InnerInterface
(
"ICriteriaAdd"
);
criteriaAddInterface
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
criteriaAddInterface
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
CommentTools
.
addInterfaceComment
(
criteriaAddInterface
,
introspectedTable
);
CommentTools
.
addInterfaceComment
(
criteriaAddInterface
,
introspectedTable
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"."
+
innerClass
.
getType
().
getShortName
()+
"增加接口ICriteriaAdd"
);
// ICriteriaAdd增加接口add
// ICriteriaAdd增加接口add
Method
addMethod
=
new
Method
(
"add"
);
Method
addMethod
=
new
Method
(
"add"
);
...
@@ -117,7 +122,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
...
@@ -117,7 +122,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
addMethod
.
addParameter
(
new
Parameter
(
innerClass
.
getType
(),
"add"
));
addMethod
.
addParameter
(
new
Parameter
(
innerClass
.
getType
(),
"add"
));
CommentTools
.
addGeneralMethodComment
(
addMethod
,
introspectedTable
);
CommentTools
.
addGeneralMethodComment
(
addMethod
,
introspectedTable
);
criteriaAddInterface
.
addMethod
(
addMethod
);
criteriaAddInterface
.
addMethod
(
addMethod
);
logger
.
debug
(
"itfsw
:Criteria.ICriteriaAdd增加接口
add"
);
logger
.
debug
(
"itfsw
(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"."
+
innerClass
.
getType
().
getShortName
()+
"."
+
criteriaAddInterface
.
getType
().
getShortName
()+
"增加方法
add"
);
InnerClass
innerClassWrapper
=
new
InnerInterfaceWrapperToInnerClass
(
criteriaAddInterface
);
InnerClass
innerClassWrapper
=
new
InnerInterfaceWrapperToInnerClass
(
criteriaAddInterface
);
innerClass
.
addInnerClass
(
innerClassWrapper
);
innerClass
.
addInnerClass
(
innerClassWrapper
);
...
@@ -135,6 +140,27 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
...
@@ -135,6 +140,27 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
method
.
addBodyLine
(
"return this;"
);
method
.
addBodyLine
(
"return this;"
);
CommentTools
.
addGeneralMethodComment
(
method
,
introspectedTable
);
CommentTools
.
addGeneralMethodComment
(
method
,
introspectedTable
);
innerClass
.
addMethod
(
method
);
innerClass
.
addMethod
(
method
);
logger
.
debug
(
"itfsw:Criteria增加方法andIf"
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"."
+
innerClass
.
getType
().
getShortName
()+
"增加方法andIf"
);
}
/**
* Example增强了setOrderByClause方法,新增orderBy(String orderByClause)方法直接返回example,增强链式调用,可以一路.下去了。
*
* @param topLevelClass
* @param introspectedTable
*/
private
void
addOrderByMethodToExample
(
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
){
// 添加orderBy
Method
method
=
new
Method
(
"orderBy"
);
method
.
setVisibility
(
JavaVisibility
.
PUBLIC
);
method
.
setReturnType
(
topLevelClass
.
getType
());
method
.
addParameter
(
new
Parameter
(
FullyQualifiedJavaType
.
getStringInstance
(),
"orderByClause"
));
method
.
addBodyLine
(
"this.setOrderByClause(orderByClause);"
);
method
.
addBodyLine
(
"return this;"
);
CommentTools
.
addGeneralMethodComment
(
method
,
introspectedTable
);
topLevelClass
.
addMethod
(
method
);
logger
.
debug
(
"itfsw(Example增强插件):"
+
topLevelClass
.
getType
().
getShortName
()+
"增加方法orderBy"
);
}
}
}
}
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