From c654ffc0c83fc85e3489b14b3cb0c46b35b12916 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 29 Apr 2023 18:41:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=A0=B9=E6=8D=AE=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E5=AD=97=E6=AE=B5=E8=BF=9B=E8=A1=8C=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/PagingAndSortingQueryParams.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java b/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java index 6d65700..3d261b3 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java @@ -16,11 +16,14 @@ package xyz.zhouxy.plusone.commons.util; +import java.util.List; import java.util.Set; import javax.annotation.Nullable; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; import xyz.zhouxy.plusone.commons.annotation.Overridable; @@ -37,14 +40,14 @@ import xyz.zhouxy.plusone.commons.annotation.Overridable; */ public class PagingAndSortingQueryParams { - protected @Nullable String orderBy; + protected final List orderBy = Lists.newLinkedList(); protected int size; protected long pageNum; private final Set sortableColNames; public PagingAndSortingQueryParams() { - sortableColNames = ImmutableSet.of(); + this.sortableColNames = ImmutableSet.of(); } public PagingAndSortingQueryParams(String... sortableColNames) { @@ -57,8 +60,8 @@ public class PagingAndSortingQueryParams { // Getters @Nullable - public final String getOrderBy() { - return this.orderBy; + public final List getOrderBy() { + return ImmutableList.copyOf(this.orderBy); } public final int getSize() { @@ -77,12 +80,15 @@ public class PagingAndSortingQueryParams { // Setters - public final void setOrderBy(@Nullable String orderBy) { - if (orderBy != null) { - Assert.isTrue(this.sortableColNames.contains(orderBy), - "The column name must be in the set of sortable columns."); + public final void setOrderBy(@Nullable List orderBy) { + this.orderBy.clear(); + if (orderBy != null && !orderBy.isEmpty()) { + for (String colName : orderBy) { + Assert.isTrue(this.sortableColNames.contains(colName), + "The column name must be in the set of sortable columns."); + } + this.orderBy.addAll(orderBy); } - this.orderBy = orderBy; } public final void setSize(@Nullable Integer size) {