solr java代码

2021-05-18 15:30

阅读:459

import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; public class PageListRequest { /** * 搜索的关键字 */ private String term; /** * 排序的字段 */ private String sort; /** * 排序的方向 */ private String direction; /** * 页码从1开始 */ private int page; /** * 条数 */ private int pageSize; public String getSort() { return sort; } public void setSort(String sort) { this.sort = sort; } public String getDirection() { return direction; } public void setDirection(String direction) { this.direction = direction; } public int getPage() { return page; } public void setPage(int page) { this.page = page; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public String getTerm() { return term; } public void setTerm(String term) { this.term = term; } public Sort.Direction getDirection(Sort.Direction defaultDirection) { if (StringUtils.isBlank(direction)) { return defaultDirection; } return Sort.Direction.valueOf(direction); } public Sort getSort(String defaultSortField, Sort.Direction defaultDirection) { if (StringUtils.isNotBlank(sort)) { Sort sort = new Sort(getDirection(defaultDirection), this.sort); return sort; } else { Sort sort = new Sort(getDirection(defaultDirection), defaultSortField); return sort; } } public Pageable getPageable(String defaultSortField, Sort.Direction defaultDirection) { // Pageable 页码是从0开始的,所以要减1操作 PageRequest pageRequest = new PageRequest(this.page - 1, this.pageSize, getSort(defaultSortField, defaultDirection)); return pageRequest; } public Pageable getPageable(Sort defaultSort) { // Pageable 页码是从0开始的,所以要减1操作 PageRequest pageRequest = new PageRequest(this.page - 1, this.pageSize, defaultSort); return pageRequest; } }


评论


亲,登录后才可以留言!