How to map Page to Page in spring-data-rest

后端 未结 9 1742
太阳男子
太阳男子 2021-01-30 12:37

When I hit the database with PagingAndSortingRepository.findAll(Pageable) I get Page. However, I want to expose DTO\'s to the clien

9条回答
  •  甜味超标
    2021-01-30 13:19

    You can use Page.map by simply doing this:

    public Page toPageObjectDto(Page objects) {
        Page dtos  = objects.map(this::convertToObjectDto);
        return dtos;
    }
    
    private ObjectDto convertToObjectDto(Object o) {
        ObjectDto dto = new ObjectDto();
        //conversion here
        return dto;
    }
    
        

    提交回复
    热议问题