Sfoglia il codice sorgente

优化 page 当 size 小于 0 自动调整为 list 模式

hubin 7 anni fa
parent
commit
c298c375d8

+ 2 - 2
build.gradle

@@ -56,7 +56,7 @@ ext {
 
 allprojects {
     group = 'com.baomidou'
-    version = '3.0-gamma'
+    version = '3.0.0-RELEASE'
 }
 
 description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"
@@ -117,7 +117,7 @@ subprojects {
             author true
             version true
             failOnError false
-            links "http://docs.oracle.com/javase/7/docs/api"
+            links "http://docs.oracle.com/javase/8/docs/api"
         }
     }
 

+ 2 - 13
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/IPage.java

@@ -72,17 +72,6 @@ public interface IPage<T> {
         return true;
     }
 
-    /**
-     * <p>
-     * 集合模式,不分页返回集合结果【 默认:false 】
-     * </p>
-     *
-     * @return true 是 / false 否
-     */
-    default boolean listMode() {
-        return false;
-    }
-
     /**
      * <p>
      * 计算当前分页偏移量
@@ -140,7 +129,7 @@ public interface IPage<T> {
      *
      * @return
      */
-    Long getTotal();
+    long getTotal();
 
     /**
      * <p>
@@ -152,7 +141,7 @@ public interface IPage<T> {
      *
      * @return 当前对象
      */
-    IPage<T> setTotal(Long total);
+    IPage<T> setTotal(long total);
 
     /**
      * <p>

+ 4 - 11
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/PaginationInterceptor.java

@@ -120,25 +120,18 @@ public class PaginationInterceptor extends SqlParserHandler implements Intercept
         }
 
         /**
-         * 不需要分页的场合
+         * 非参数模式 ThreadLocal 变量处理的分页
          */
         if (null == page) {
             if (localPage) {
-                // 采用ThreadLocal变量处理的分页
                 page = PageHelper.getPage();
-                if (null == page) {
-                    return invocation.proceed();
-                }
-            } else {
-                // 无需分页
-                return invocation.proceed();
             }
         }
 
         /**
-         * 集合模式无需分页返回结果集
+         * 不需要分页的场合,如果 size 小于 0 返回结果集
          */
-        if (null != page && page.listMode()) {
+        if (null == page || page.getSize() < 0) {
             return invocation.proceed();
         }
 
@@ -147,7 +140,7 @@ public class PaginationInterceptor extends SqlParserHandler implements Intercept
         DbType dbType = StringUtils.isNotEmpty(dialectType) ? DbType.getDbType(dialectType) : JdbcUtils.getDbType(connection.getMetaData().getURL());
 
         boolean orderBy = true;
-        if (null != page.getTotal() && page.getTotal().equals(0L)) {
+        if (page.getTotal() == 0) {
             SqlInfo sqlInfo = SqlUtils.getOptimizeCountSql(page.optimizeCountSql(), sqlParser, originalSql);
             orderBy = sqlInfo.isOrderBy();
             this.queryTotal(overflow, sqlInfo.getSql(), mappedStatement, boundSql, page, connection);

+ 3 - 18
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/Page.java

@@ -41,7 +41,7 @@ public class Page<T> implements IPage<T>, Serializable {
     /**
      * 总数,当 total 为 null 或者大于 0 分页插件不在查询总数
      */
-    private Long total = 0L;
+    private long total = 0;
     /**
      * 每页显示条数,默认 10
      */
@@ -68,13 +68,6 @@ public class Page<T> implements IPage<T>, Serializable {
      * </p>
      */
     private boolean optimizeCountSql = true;
-    /**
-     * <p>
-     * 集合模式,不分页返回集合结果
-     * </p>
-     */
-    private boolean listMode = false;
-
 
     public Page() {
         // to do nothing
@@ -134,13 +127,13 @@ public class Page<T> implements IPage<T>, Serializable {
     }
 
     @Override
-    public Page<T> setTotal(Long total) {
+    public Page<T> setTotal(long total) {
         this.total = total;
         return this;
     }
 
     @Override
-    public Long getTotal() {
+    public long getTotal() {
         return this.total;
     }
 
@@ -209,12 +202,4 @@ public class Page<T> implements IPage<T>, Serializable {
         this.optimizeCountSql = optimizeCountSql;
     }
 
-    @Override
-    public boolean listMode() {
-        return listMode;
-    }
-
-    public void setListMode(boolean listMode) {
-        this.listMode = listMode;
-    }
 }