use of cn.hutool.db.PageResult in project Jpom by dromara.
the class BaseDbCommonService method listPage.
/**
* 分页查询
*
* @param where 条件
* @param page 分页
* @return 结果
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public PageResultDto<T> listPage(Entity where, Page page) {
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return PageResultDto.EMPTY;
}
where.setTableName(getTableName());
PageResult<Entity> pageResult;
Db db = Db.use();
db.setWrapper((Character) null);
try {
pageResult = db.page(where, page);
} catch (Exception e) {
throw warpException(e);
}
//
List<T> list = pageResult.stream().map(entity -> {
T entityToBean = this.entityToBean(entity, this.tClass);
this.fillSelectResult(entityToBean);
return entityToBean;
}).collect(Collectors.toList());
PageResultDto<T> pageResultDto = new PageResultDto(pageResult);
pageResultDto.setResult(list);
if (pageResultDto.isEmpty() && pageResultDto.getPage() > 1) {
Assert.state(pageResultDto.getTotal() <= 0, "筛选的分页有问题,当前页码查询不到任何数据");
}
return pageResultDto;
}
Aggregations