优化:
生成的代码优化,pagesize大于等于10000时,代表不分页,用于内部调用getlist使用
This commit is contained in:
@@ -15,7 +15,9 @@ import java.util.List;
|
||||
public abstract class AbstractWithLimitPlugin extends PluginAdapter implements ISelectSelectivePluginHook {
|
||||
|
||||
private final static int DEFAULT_START_PAGE = 1;
|
||||
private final static int DEFAULT_IGNORE_PAGE_SIZE = 10000;
|
||||
private int startPage = 1;
|
||||
private int ignorePageSize = DEFAULT_IGNORE_PAGE_SIZE;
|
||||
|
||||
@Override
|
||||
public boolean validate(List<String> list) {
|
||||
@@ -26,12 +28,22 @@ public abstract class AbstractWithLimitPlugin extends PluginAdapter implements I
|
||||
public void initialized(IntrospectedTable introspectedTable) {
|
||||
super.initialized(introspectedTable);
|
||||
this.startPage = DEFAULT_START_PAGE;
|
||||
String ignorePageSizeProperty = this.properties.getProperty("ignorePageSize");
|
||||
if (ignorePageSizeProperty != null && ignorePageSizeProperty.trim().length() > 0) {
|
||||
try {
|
||||
this.ignorePageSize = Integer.parseInt(ignorePageSizeProperty.trim());
|
||||
} catch (NumberFormatException ignored) {
|
||||
this.ignorePageSize = DEFAULT_IGNORE_PAGE_SIZE;
|
||||
}
|
||||
} else {
|
||||
this.ignorePageSize = DEFAULT_IGNORE_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
|
||||
PrimitiveTypeWrapper integerWrapper = FullyQualifiedJavaType.getIntInstance().getPrimitiveTypeWrapper();
|
||||
// 添加minPageNum、defaultPageSize和maxPageSize字段
|
||||
// 添加 minPageNum、defaultPageSize、maxPageSize、ignorePageSize 字段
|
||||
Field maxPageSizeField = ElementTools.generateField(
|
||||
"maxPageSize",
|
||||
JavaVisibility.PROTECTED,
|
||||
@@ -40,6 +52,14 @@ public abstract class AbstractWithLimitPlugin extends PluginAdapter implements I
|
||||
);
|
||||
topLevelClass.addField(maxPageSizeField);
|
||||
|
||||
Field ignorePageSizeField = ElementTools.generateField(
|
||||
"ignorePageSize",
|
||||
JavaVisibility.PROTECTED,
|
||||
integerWrapper,
|
||||
this.ignorePageSize + ""
|
||||
);
|
||||
topLevelClass.addField(ignorePageSizeField);
|
||||
|
||||
Field defaultPageSizeField = ElementTools.generateField(
|
||||
"defaultPageSize",
|
||||
JavaVisibility.PROTECTED,
|
||||
@@ -80,6 +100,12 @@ public abstract class AbstractWithLimitPlugin extends PluginAdapter implements I
|
||||
Method mGetMaxPageSize = ElementTools.generateGetterMethod(maxPageSizeField);
|
||||
FormatTools.addMethodWithBestPosition(topLevelClass, mGetMaxPageSize);
|
||||
|
||||
Method mSetIgnorePageSize = ElementTools.generateSetterMethod(ignorePageSizeField);
|
||||
FormatTools.addMethodWithBestPosition(topLevelClass, mSetIgnorePageSize);
|
||||
|
||||
Method mGetIgnorePageSize = ElementTools.generateGetterMethod(ignorePageSizeField);
|
||||
FormatTools.addMethodWithBestPosition(topLevelClass, mGetIgnorePageSize);
|
||||
|
||||
Method mSetDefaultPageSize = ElementTools.generateSetterMethod(defaultPageSizeField);
|
||||
FormatTools.addMethodWithBestPosition(topLevelClass, mSetDefaultPageSize);
|
||||
|
||||
@@ -144,6 +170,11 @@ public abstract class AbstractWithLimitPlugin extends PluginAdapter implements I
|
||||
usePage,
|
||||
"pageSize = pageSize == null || pageSize <= 0 ? this.defaultPageSize : pageSize;",
|
||||
"pageNum = pageNum == null || pageNum < this.minPageNum ? this.minPageNum : pageNum;",
|
||||
"if (pageSize >= this.ignorePageSize) {",
|
||||
"this.rows = null;",
|
||||
"this.offset = null;",
|
||||
"return this;",
|
||||
"}",
|
||||
"int cPageSize = pageSize > this.maxPageSize ? this.maxPageSize: pageSize;",
|
||||
"this.offset = (pageNum - this.minPageNum) * cPageSize;",
|
||||
"this.rows = cPageSize;",
|
||||
|
||||
Reference in New Issue
Block a user