Pagination in Spring Saving Data for Nested Resources

When the following URL is visited, I get fingerprints in response

/api/userPosts/

{
  "_links" : {
    "self" : {
      "href" : "/api/userPosts{?page,size,sort}",
      "templated" : true
    },
    "next" : {
      "href" : api/userPosts?page=1&size=20{&sort}",
      "templated" : true
    }
  },
  "_embedded" : {
    "userPosts" : [ {
     ...

However, when visiting the following URL there is no page without Spring Data REST fields -

/api/users/4/userPosts

{
  "_embedded" : {
    "userPosts" : [ {

Both UserRepository and UserPostRepository are paginated JPARepository. As a result, the second URL throws an excess of GC invoice because the number of rows for the returned results is huge.

@RepositoryRestResource(excerptProjection = UserProjection.class)
public interface UserRepository extends BaseRepository<User, Integer>, UserRepositoryCustom {

}

public interface UserPostRepository extends BaseRepository<UserPost, Long> {

}


@NoRepositoryBean
public interface BaseRepository<T, N extends Serializable> extends JpaRepository<T, N>, QueryDslPredicateExecutor<T> {

}

Any way to have a pagination with a second url?

+1
source share

Source: https://habr.com/ru/post/1548601/


All Articles