deason 5 lat temu
rodzic
commit
d354f97138

+ 6 - 1
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/jpa/OrderBuilder.java

@@ -19,6 +19,7 @@ import java.util.List;
  * @since: 2018/10/23
  */
 public class OrderBuilder {
+
     private List<Order> orders;
 
     public OrderBuilder() {
@@ -39,15 +40,19 @@ public class OrderBuilder {
         if (orders.size() == 0) {
             return null;
         }
+
         List<Sort.Order> list = new ArrayList<>();
         for (Order order : orders) {
             list.add(new Sort.Order(order.getDirection(), order.getFieldName()));
         }
-        return new Sort(list);
+
+        return Sort.by(list);
     }
 
     public static class Order {
+
         private String fieldName;
+
         private Sort.Direction direction;
 
         private Order(String fieldName, Sort.Direction direction) {

+ 16 - 5
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/jpa/SpecUtils.java

@@ -15,7 +15,6 @@ import org.springframework.data.jpa.domain.Specifications;
 
 import javax.persistence.criteria.Path;
 import javax.persistence.criteria.Predicate;
-import javax.validation.constraints.NotNull;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -26,10 +25,12 @@ import java.util.List;
  * @since: 2018/10/17
  */
 public class SpecUtils {
+
     /**
      * 默认当前页数
      */
     public static final int DEFAULT_PAGE_NO = 1;
+
     /**
      * 默认每页条数
      */
@@ -43,7 +44,7 @@ public class SpecUtils {
      * @return
      */
     public static Pageable buildPageable(Integer pageNo, Integer pageSize) {
-        return buildPageable(pageNo, pageSize, null);
+        return buildPageable(pageNo, pageSize, Sort.unsorted());
     }
 
     /**
@@ -58,10 +59,12 @@ public class SpecUtils {
         if (pageNo == null || pageNo < 1) {
             pageNo = DEFAULT_PAGE_NO;
         }
+
         if (pageSize == null || pageSize < 1) {
             pageSize = DEFAULT_PAGE_SIZE;
         }
-        return new PageRequest(pageNo - 1, pageSize, sort);
+
+        return PageRequest.of(pageNo - 1, pageSize, sort);
     }
 
     /**
@@ -89,17 +92,20 @@ public class SpecUtils {
         if (searchers == null || searchers.size() == 0) {
             return null;
         }
+
         return (root, query, builder) -> {
             List<Predicate> predicates = new ArrayList<>();
             for (SearchBuilder.Searcher filter : searchers) {
                 if (filter.getFieldName() == null || "".equals(filter.getFieldName())) {
                     continue;
                 }
+
                 String[] names = filter.getFieldName().split("\\.");
                 Path expression = root.get(names[0]);
                 for (int i = 1; i < names.length; i++) {
                     expression = expression.get(names[i]);
                 }
+
                 switch (filter.getOp()) {
                     case EQ:
                         predicates.add(builder.equal(expression, filter.getValue()));
@@ -142,6 +148,7 @@ public class SpecUtils {
                         break;
                 }
             }
+
             if (!predicates.isEmpty()) {
                 if (isOR) {
                     //将所有条件用 or 联合起来
@@ -161,10 +168,11 @@ public class SpecUtils {
      * @param specs
      * @return
      */
-    public static Specification andMerge(@NotNull Specification... specs) {
+    public static Specification andMerge(Specification... specs) {
         if (specs == null || specs.length == 0) {
             return null;
         }
+
         Specifications result = null;
         for (int i = 0; i < specs.length; i++) {
             if (i == 0) {
@@ -173,6 +181,7 @@ public class SpecUtils {
             }
             result = Specifications.where(result).and(specs[i]);
         }
+
         return result;
     }
 
@@ -184,10 +193,11 @@ public class SpecUtils {
      * @param specs
      * @return
      */
-    public static Specification orMerge(@NotNull Specification... specs) {
+    public static Specification orMerge(Specification... specs) {
         if (specs == null || specs.length == 0) {
             return null;
         }
+
         Specifications result = null;
         for (int i = 0; i < specs.length; i++) {
             if (i == 0) {
@@ -196,6 +206,7 @@ public class SpecUtils {
             }
             result = Specifications.where(result).or(specs[i]);
         }
+
         return result;
     }