All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.github.aidensuen.mongo.pagehelper.PageMethod Maven / Gradle / Ivy
package com.github.aidensuen.mongo.pagehelper;
import org.springframework.data.domain.Sort;
import java.util.Properties;
/**
* thanks https://github.com/pagehelper/
*/
public abstract class PageMethod {
protected static final ThreadLocal LOCAL_PAGE = new ThreadLocal<>();
protected static boolean DEFAULT_COUNT = true;
protected static void setLocalPage(Page page) {
LOCAL_PAGE.set(page);
}
public static Page getLocalPage() {
return LOCAL_PAGE.get();
}
public static void clearPage() {
LOCAL_PAGE.remove();
}
public static Page startPage(PageObject pageObject, Object params) {
Page page = pageObject.getPageFromObject(params);
setLocalPage(page);
return page;
}
public static Page startPage(int pageNum, int pageSize) {
return startPage(pageNum, pageSize, DEFAULT_COUNT);
}
public static Page startPage(int pageNum, int pageSize, boolean count) {
return startPage(pageNum, pageSize, count, Sort.unsorted());
}
public static Page startPage(int pageNum, int pageSize, Sort sort) {
return startPage(pageNum, pageSize, DEFAULT_COUNT, sort);
}
public static Page startPage(int pageNum, int pageSize, Object lastId) {
return startPage(pageNum, pageSize, DEFAULT_COUNT, lastId);
}
public static Page startPage(int pageNum, int pageSize, boolean count, Object lastId) {
Page page = startPage(pageNum, pageSize, count, Sort.unsorted());
page.setLastId(lastId);
return page;
}
public static Page startPage(int pageNum, int pageSize, boolean count, Sort sort) {
Page page = Page.of(pageNum, pageSize, count, sort);
setLocalPage(page);
return page;
}
public static Page offsetPage(int skip, int limit) {
return offsetPage(skip, limit, DEFAULT_COUNT);
}
public static Page offsetPage(int skip, int limit, boolean count) {
Page page = Page.of(new int[]{skip, limit}, count);
setLocalPage(page);
return page;
}
public static void setStaticProperties(Properties properties) {
if (properties != null) {
DEFAULT_COUNT = Boolean.valueOf(properties.getProperty("defaultCount", "true"));
}
}
}