List<Sort.Order> orders = new ArrayList<>();
// Sort.Direction.DESC Sort.Direction.ASC
orders.add(new Sort.Order(Sort.Direction.DESC, "字段名"));
orders.add(new Sort.Order(Sort.Direction.DESC, "字段名"));
Sort sort = Sort.by(orders);
//分页查询
pageable = PageRequest.of(pageNumber, pageSize, sort);
Page<实体名> findByCode(code, pageable)
//不分页
List<实体名> findByCode(code,sort)
pageable种本身就有排序sort 默认为unsorted
如果是下面的写法则会报错
Page<实体名> findByCode(code, pageAble,sort)
报错信息为 Method must not have Pageable *and* Sort parameter.
Use sorting capabilities on Pageable instead!
方法不能具有Pageable*和*Sort参数。改用Pageable上的排序功能!
用了上述方法后的pageable