当我想把一个List对象,封装成SpringData中的Page对象时

代码实现

   @GetMapping("/list")
   public List<CustomerDTO> getS1(){
    return customerMapper.toCustomerDto(customerService.findAll());
    }

    // Page<CustomersEntity>
    @GetMapping("/page")
    public Page<CustomersEntity> page1(){
//        PageRequest pageRequest = PageRequest.of(0, 20, Sort.Direction.DESC/*,""*/);
        PageRequest pageRequest = PageRequest.of(0, 20, Sort.Direction.DESC,"customerNumber");
        Page<CustomersEntity> all = customerRepo.findAll(pageRequest);
        return all;
    }

返回数据

当我稍微看了下page,是这样的

下一篇,List 对象转 Page