提交 66100e6d authored 作者: Whispa's avatar Whispa

commit

上级 a0cd5c24
...@@ -43,9 +43,10 @@ public class ItemController { ...@@ -43,9 +43,10 @@ public class ItemController {
@GetMapping("/queryAll") @GetMapping("/queryAll")
public Result queryAll(@RequestParam(value = "pageNum", defaultValue = "0") Integer pageNum, public Result queryAll(@RequestParam(value = "pageNum", defaultValue = "0") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) { @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
@RequestParam(value = "order", required = false) String order) {
return new Result<>(repository.findAll(PageRequest.of(pageNum,pageSize))); return new Result<>(repository.findAll(PageRequest.of(pageNum,pageSize,sort2(order))));
} }
...@@ -129,7 +130,22 @@ public class ItemController { ...@@ -129,7 +130,22 @@ public class ItemController {
private Sort sort(String order){ private Sort sort(String order){
String col = "discountPrice"; String col = "discountPrice";
return Sort.by( "desc".equals(order) ? desc(col) : asc(col)); return Sort.by(order(order,col));
}
private Sort.Order order(String order,String col){
return "desc".equals(order) ? desc(col) : asc(col);
}
private Sort sort2(String order){
String[] cols = new String[]{"itemTop","discountPrice","createTime"};
List<Sort.Order> list = new ArrayList<>();
for (String col : cols){
list.add( order(order,col) );
}
return Sort.by(list);
} }
@GetMapping("/queryItemsByLabel") @GetMapping("/queryItemsByLabel")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论