소스 검색

字典编辑:MySQL默认排序不可靠,分页查询时会出现跨页结果重复,因此加上默认排序

yucheng 3 년 전
부모
커밋
a403504835

+ 9 - 1
dmp-business/dmp-rwd-version/src/main/java/com/persagy/dmp/rwd/demand/controller/DictionaryDemandController.java

@@ -10,6 +10,7 @@ import com.persagy.dmp.common.constant.ValidEnum;
 import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.model.entity.AuditableEntity;
+import com.persagy.dmp.common.model.entity.BaseEntity;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.common.utils.JsonHelper;
 import com.persagy.dmp.common.utils.ParamCheckUtil;
@@ -181,9 +182,16 @@ public class DictionaryDemandController {
      * @param pageable
      */
     private void resetOrderItem(Page pageable) {
-        if(pageable == null || CollUtil.isEmpty(pageable.getOrders())) {
+        if(pageable == null) {
             return;
         }
+        // MySQL默认排序不可靠,分页查询时会出现跨页结果重复,因此加上默认排序
+        if(CollUtil.isEmpty(pageable.getOrders())) {
+            List<OrderItem> defaultOrders = CollUtil.newArrayList(OrderItem.asc(BaseEntity.PROP_ID));
+            pageable.setOrders(defaultOrders);
+            return;
+        }
+        // 转下划线
         List<OrderItem> orders = pageable.getOrders();
         for(OrderItem order:orders) {
             order.setColumn(StrUtil.toUnderlineCase(order.getColumn()));