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

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

    This works correctly in Spring 2.0 -

    @Override
    public Page getBooksByAuthor(String authorId, Pageable pageable) {
            Page bookEntity = iBookRepository.findByAuthorId(authorId, pageable);
            return bookEntity.map(new Function() {
    
                @Override
                public BookDto apply(BookEntity t) {
                    return new ModelMapper().map(t, BookDto.class);
                }
    
            });
        }
    

    The converter is no longer supported in Page type for Spring 2.0. Also, the Function should be used from java.util.function.Function.

提交回复
热议问题