Commit 38417972 authored by hewei's avatar hewei

ExampleEnhancedPlugin 插件增加OrderBy方法

parent ce099f81
......@@ -7,7 +7,7 @@
* 查询单条数据插件(SelectOneByExamplePlugin)
* MySQL分页插件(LimitPlugin)
* 数据Model链式构建插件(ModelBuilderPlugin)
* Example Criteria 增强插件(CriteriaBuilderPlugin
* Example Criteria 增强插件(ExampleEnhancedPlugin(CriteriaBuilderPlugin这个是老版本叫法,已经弃用)
* Example 目标包修改插件(ExampleTargetPlugin)
* 批量插入插件(BatchInsertPlugin)
* 逻辑删除插件(LogicalDeletePlugin)
......@@ -146,13 +146,14 @@ public class Test {
}
}
```
### 4. Example Criteria 增强插件(example,andIf)
* 表Example增加Criteria的快速返回example()方法。
* Criteria链式调用增强,以前如果有按条件增加的查询语句会打乱链式查询构建,现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。
### 4. Example 增强插件(example,andIf)
* Criteria的快速返回example()方法。
* Criteria链式调用增强,以前如果有按条件增加的查询语句会打乱链式查询构建,现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。
* Example增强了setOrderByClause方法,新增orderBy(String orderByClause)方法直接返回example,增强链式调用,可以一路.下去了。
插件:
```xml
<!-- Example Criteria 增强插件 -->
<plugin type="com.itfsw.mybatis.generator.plugins.CriteriaBuilderPlugin"/>
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin"/>
```
使用:
```java
......
......@@ -60,8 +60,12 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
if (!"createCriteriaInternal".equals(method.getName()))
continue;
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;
}
......@@ -83,7 +87,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
if (method.isConstructor()) {
method.addParameter(new Parameter(topLevelClass.getType(), "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 {
method.addBodyLine("return this.example;");
CommentTools.addGeneralMethodComment(method, introspectedTable);
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 {
InnerInterface criteriaAddInterface = new InnerInterface("ICriteriaAdd");
criteriaAddInterface.setVisibility(JavaVisibility.PUBLIC);
CommentTools.addInterfaceComment(criteriaAddInterface, introspectedTable);
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"."+innerClass.getType().getShortName()+"增加接口ICriteriaAdd");
// ICriteriaAdd增加接口add
Method addMethod = new Method("add");
......@@ -117,7 +122,7 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
addMethod.addParameter(new Parameter(innerClass.getType(), "add"));
CommentTools.addGeneralMethodComment(addMethod, introspectedTable);
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.addInnerClass(innerClassWrapper);
......@@ -135,6 +140,27 @@ public class ExampleEnhancedPlugin extends PluginAdapter {
method.addBodyLine("return this;");
CommentTools.addGeneralMethodComment(method, introspectedTable);
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");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment