Skip to content

Commit

Permalink
增加 defaultCount 参数,用于控制默认不带 count 查询的方法中,是否执行 count 查询,默认 true 会执行 co…
Browse files Browse the repository at this point in the history
…unt 查询,这是一个全局生效的参数,多数据源时也是统一的行为。
  • Loading branch information
abel533 committed Apr 5, 2018
1 parent 0719bf4 commit 8f472cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/github/pagehelper/PageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void afterAll() {

@Override
public void setProperties(Properties properties) {
setStaticProperties(properties);
pageParams = new PageParams();
autoDialect = new PageAutoDialect();
pageParams.setProperties(properties);
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/github/pagehelper/page/PageMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
import com.github.pagehelper.Page;
import com.github.pagehelper.util.PageObjectUtil;

import java.util.Properties;

/**
* 基础分页方法
*
* @author liuzh
*/
public abstract class PageMethod {
protected static final ThreadLocal<Page> LOCAL_PAGE = new ThreadLocal<Page>();
protected static boolean DEFAULT_COUNT = true;

/**
* 设置 Page 参数
Expand Down Expand Up @@ -96,7 +99,7 @@ public static <E> Page<E> startPage(Object params) {
* @param pageSize 每页显示数量
*/
public static <E> Page<E> startPage(int pageNum, int pageSize) {
return startPage(pageNum, pageSize, true);
return startPage(pageNum, pageSize, DEFAULT_COUNT);
}

/**
Expand Down Expand Up @@ -152,7 +155,7 @@ public static <E> Page<E> startPage(int pageNum, int pageSize, boolean count, Bo
* @param limit 每页显示数量
*/
public static <E> Page<E> offsetPage(int offset, int limit) {
return offsetPage(offset, limit, true);
return offsetPage(offset, limit, DEFAULT_COUNT);
}

/**
Expand Down Expand Up @@ -190,5 +193,16 @@ public static void orderBy(String orderBy) {
}
}

/**
* 设置参数
*
* @param properties 插件属性
*/
protected static void setStaticProperties(Properties properties){
//defaultCount,这是一个全局生效的参数,多数据源时也是统一的行为
if(properties != null){
DEFAULT_COUNT = Boolean.valueOf(properties.getProperty("defaultCount", "true"));
}
}

}

0 comments on commit 8f472cd

Please sign in to comment.