其他分享
首页 > 其他分享> > jpa Pageable

jpa Pageable

作者:互联网

public static Pageable getPageable(Map<String, Object> params) {

Pageable pageable = new Pageable() {
@Override
public int getPageNumber() {

Integer pageNumber = 1;
if (params.containsKey("page")){
pageNumber = MapUtils.getInteger(params, "page");
}

return pageNumber -1;
}

@Override
public int getPageSize() {

Integer pageSize = 20;
if (params.containsKey("size")){
pageSize = MapUtils.getInteger(params, "size");
}

return pageSize;
}

@Override
public long getOffset() {
return 0;
}

@Override
public Sort getSort() {

String sortStr = MapUtils.getString(params, "sort");

Sort sort = Sort.unsorted();

if (StringUtils.isNotBlank(sortStr)) {
String[] split = sortStr.split(",");

if (split.length == 1) {
sort = Sort.by(split[0]);
} else if (split.length == 2) {
sort = Sort.by(Sort.Direction.fromString(split[1]), split[0]);
}
}
return sort;
}

@Override
public Pageable next() {
return null;
}

@Override
public Pageable previousOrFirst() {
return null;
}

@Override
public Pageable first() {
return null;
}

@Override
public boolean hasPrevious() {
return false;
}
};

return pageable;
}
 

标签:Sort,return,Pageable,jpa,split,Override,public
来源: https://www.cnblogs.com/yaoyao66123/p/13578901.html