From bb30ae7086329a03ccd44d510328321e67745397 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 2 Sep 2021 10:46:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E8=A1=A8=E6=A0=BC=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E9=A1=B5=E6=9C=80=E5=90=8E=E9=A1=B9=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8F=98=E6=88=90=E6=9A=82=E6=97=A0=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/utils/ServletUtils.java | 16 ++++++++++++++++ .../core/web/controller/BaseController.java | 3 ++- .../ruoyi/common/core/web/page/PageDomain.java | 17 +++++++++++++++++ .../common/core/web/page/TableSupport.java | 6 ++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java index 51a6141e..1142e412 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java @@ -63,6 +63,22 @@ public class ServletUtils return Convert.toInt(getRequest().getParameter(name), defaultValue); } + /** + * 获取Boolean参数 + */ + public static Boolean getParameterToBool(String name) + { + return Convert.toBool(getRequest().getParameter(name)); + } + + /** + * 获取Boolean参数 + */ + public static Boolean getParameterToBool(String name, Boolean defaultValue) + { + return Convert.toBool(getRequest().getParameter(name), defaultValue); + } + /** * 获取request */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java index 1b423d63..64169511 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java @@ -55,7 +55,8 @@ public class BaseController if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) { String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); - PageHelper.startPage(pageNum, pageSize, orderBy); + Boolean reasonable = pageDomain.getReasonable(); + PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable); } } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/PageDomain.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/PageDomain.java index e97b4e55..413aabf2 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/PageDomain.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/PageDomain.java @@ -21,6 +21,9 @@ public class PageDomain /** 排序的方向desc或者asc */ private String isAsc = "asc"; + /** 分页参数合理化 */ + private Boolean reasonable = true; + public String getOrderBy() { if (StringUtils.isEmpty(orderByColumn)) @@ -81,4 +84,18 @@ public class PageDomain this.isAsc = isAsc; } } + + public Boolean getReasonable() + { + if (StringUtils.isNull(reasonable)) + { + return Boolean.TRUE; + } + return reasonable; + } + + public void setReasonable(Boolean reasonable) + { + this.reasonable = reasonable; + } } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableSupport.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableSupport.java index 351064e6..c6bd3dda 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableSupport.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/page/TableSupport.java @@ -29,6 +29,11 @@ public class TableSupport */ public static final String IS_ASC = "isAsc"; + /** + * 分页参数合理化 + */ + public static final String REASONABLE = "reasonable"; + /** * 封装分页对象 */ @@ -39,6 +44,7 @@ public class TableSupport pageDomain.setPageSize(ServletUtils.getParameterToInt(PAGE_SIZE)); pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN)); pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC)); + pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE)); return pageDomain; }