Commit dbda556e by Jan Hrabal

small paging improvements

parent 1949ff93
...@@ -149,7 +149,7 @@ public abstract class AbstractHibernateRepository { ...@@ -149,7 +149,7 @@ public abstract class AbstractHibernateRepository {
sortedCriteria(c, pagingInfo); sortedCriteria(c, pagingInfo);
return new Page<>(pagingInfo.getPage(), pagingInfo.getPageSize(), pagesCount, count, c.list(), pagingInfo.getField(), pagingInfo.getTrend()); return new Page<>(pagingInfo.getPage(), pagesCount, pagingInfo.getPageSize(), count, c.list(), pagingInfo.getField(), pagingInfo.getTrend());
} }
......
...@@ -94,12 +94,12 @@ public class ListHelper { ...@@ -94,12 +94,12 @@ public class ListHelper {
field = defaultField; field = defaultField;
} }
if (trend == null) { if (!StringUtils.hasText(trend)) {
if (defaultTrend != null) { if (defaultTrend != null) {
st = defaultTrend; st = defaultTrend;
} }
} else { } else {
st = "desc".equalsIgnoreCase(trend) ? SortTrend.DESCENDING : SortTrend.ASCENDING; st = SortTrend.parse(trend);
} }
if (!StringUtils.hasText(field) || st == null) { if (!StringUtils.hasText(field) || st == null) {
......
...@@ -128,8 +128,8 @@ public class Page<T> { ...@@ -128,8 +128,8 @@ public class Page<T> {
* *
* @return the trend * @return the trend
*/ */
public SortTrend getTrend() { public String getTrend() {
return trend; return trend == null ? null : trend.getTrend();
} }
/** /**
......
...@@ -12,7 +12,34 @@ package com.jh.boot.web.list; ...@@ -12,7 +12,34 @@ package com.jh.boot.web.list;
public enum SortTrend { public enum SortTrend {
/** The ascending. */ /** The ascending. */
ASCENDING, ASCENDING("asc"),
/** The descending. */ /** The descending. */
DESCENDING DESCENDING("desc");
private String trend;
private SortTrend(String trend) {
this.trend = trend;
}
public String getTrend() {
return trend;
}
@Override
public String toString() {
return trend;
}
public static SortTrend parse(String s) {
for (SortTrend st : values()) {
if (st.trend.equalsIgnoreCase(s) || st.name().equalsIgnoreCase(s)) {
return st;
}
}
return null;
}
} }
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