From c9db3828a30d4076a8ed1fb3bb5fcaa170626bcb Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 24 Dec 2024 17:38:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=B7=A5=E5=85=B7=E7=B1=BB?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/model/dto/PagingAndSortingQueryParams.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/model/dto/PagingAndSortingQueryParams.java b/src/main/java/xyz/zhouxy/plusone/commons/model/dto/PagingAndSortingQueryParams.java index 9c04fd3..6eb0106 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/model/dto/PagingAndSortingQueryParams.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/model/dto/PagingAndSortingQueryParams.java @@ -27,7 +27,9 @@ import javax.annotation.Nullable; import com.google.common.collect.ImmutableMap; import xyz.zhouxy.plusone.commons.annotation.Virtual; +import xyz.zhouxy.plusone.commons.collection.CollectionTools; import xyz.zhouxy.plusone.commons.util.AssertTools; +import xyz.zhouxy.plusone.commons.util.RegexTools; import xyz.zhouxy.plusone.commons.util.StringTools; /** @@ -49,12 +51,12 @@ public class PagingAndSortingQueryParams { private Long pageNum; private List orderBy; - private static final Pattern sortStrPattern = Pattern.compile("^[a-zA-Z]\\w+-(desc|asc|DESC|ASC)$"); + private static final Pattern SORT_STR_PATTERN = Pattern.compile("^[a-zA-Z]\\w+-(desc|asc|DESC|ASC)$"); private final Map sortableProperties; public PagingAndSortingQueryParams(@Nonnull Map sortableProperties) { - AssertTools.checkArgument(sortableProperties != null && !sortableProperties.isEmpty(), + AssertTools.checkArgument(CollectionTools.isNotEmpty(sortableProperties), "Sortable properties can not be empty."); sortableProperties.forEach((k, v) -> AssertTools.checkArgument(StringTools.isNotBlank(k) && StringTools.isNotBlank(v), @@ -102,7 +104,7 @@ public class PagingAndSortingQueryParams { } private SortableProperty generateSortableProperty(String orderByStr) { - AssertTools.checkArgument(PagingAndSortingQueryParams.sortStrPattern.matcher(orderByStr).matches()); + AssertTools.checkArgument(RegexTools.matches(orderByStr, SORT_STR_PATTERN)); String[] propertyNameAndOrderType = orderByStr.split("-"); AssertTools.checkArgument(propertyNameAndOrderType.length == 2);