public PageResult<Brand> queryBrandByPage(Integer page, Integer rows, String sortBy, Boolean desc, String key) { //分頁 PageHelper.startPage(page,rows); //過濾 Example example = new Example(Brand.class); if (StringUtils.isNotBlank(key)){ example.createCriteria().orLike("name","%"+key+"%") .orEqualTo("letter",key.toUpperCase()); } //排序 if (StringUtils.isNotBlank(sortBy)){ String orderByclause = sortBy+(desc?" DESC":" ASC"); example.setOrderByClause(orderByclause); } //查詢 List<Brand> list = brandMapper.selectByExample(example); if (CollectionUtils.isEmpty(list)){ throw new ShopException(ExceptionEnum.BRAND_NOT_FIND); } //解析分頁結果 PageInfo<Brand> info = new PageInfo<>(list); return new PageResult<>(info.getTotal(),list); }
public PageResult<Brand> queryBrandByPage(Integer page, Integer rows, String sortBy, Boolean desc, String key) {
//分頁
PageHelper.startPage(page,rows);
//過濾
Example example = new Example(Brand.class);
if (StringUtils.isNotBlank(key)){
example.createCriteria().orLike("name","%"+key+"%")
.orEqualTo("letter",key.toUpperCase());
}
//排序
if (StringUtils.isNotBlank(sortBy)){
String orderByclause = sortBy+(desc?" DESC":" ASC");
example.setOrderByClause(orderByclause);
}
//查詢
List<Brand> list = brandMapper.selectByExample(example);
if (CollectionUtils.isEmpty(list)){
throw new ShopException(ExceptionEnum.BRAND_NOT_FIND);
}
//解析分頁結果
PageInfo<Brand> info = new PageInfo<>(list);
return new PageResult<>(info.getTotal(),list);
}