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());
} }
......
/* /*
* Created on 25. 8. 2017 18:29:24 * Created on 25. 8. 2017 18:29:24
* *
*/ */
package com.jh.boot.web.list; package com.jh.boot.web.list;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* The Interface DefaultSorting. * The Interface DefaultSorting.
* *
* @author Jan Hrabal * @author Jan Hrabal
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.PARAMETER}) @Target({ElementType.METHOD, ElementType.PARAMETER})
public @interface DefaultSorting { public @interface DefaultSorting {
/** /**
* Field. * Field.
* *
* @return the string * @return the string
*/ */
String field(); String field();
/** /**
* Trend. * Trend.
* *
* @return the sort trend * @return the sort trend
*/ */
SortTrend trend() default SortTrend.ASCENDING; SortTrend trend() default SortTrend.ASCENDING;
} }
...@@ -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();
} }
/** /**
......
/* /*
* Created on 30. 10. 2016 7:32:25 * Created on 30. 10. 2016 7:32:25
* *
*/ */
package com.jh.boot.web.list; package com.jh.boot.web.list;
/** /**
* The Enum SortTrend. * The Enum SortTrend.
* *
* @author Jan Hrabal * @author Jan Hrabal
*/ */
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