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

后端 未结 9 1652
太阳男子
太阳男子 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:26

    In Spring Data 2, the Page map method takes a Function instead of a Converter, but it still works basically the same as @Ali Dehghani described.

    Using Function:

    Page entities = objectEntityRepository.findAll(pageable);
    Page dtoPage = entities.map(new Function() {
        @Override
        public ObjectDto apply(ObjectEntity entity) {
            ObjectDto dto = new ObjectDto();
            // Conversion logic
    
            return dto;
        }
    });
    

提交回复
热议问题