0

Iまし以下のクラス:PagingAndSortingRepositoryページネーション情報

@RepositoryRestResource(collectionResourceRel = "books", path = "books") 
public interface BookRepository extends PagingAndSortingRepository<Book, Long> { 
    List<Book> findByTitle(Pageable pageable, @Param("title") String title); 
} 

私は素敵なページネーション情報を得るが、findByTitle方法で、私はページネーション機能しますが、何の次の(任意のページネーション情報を取得しません/図書呼び出すとき、前のリンクや「カウント」フィールド)

/booksレスポンスで同じHATEOASエクスペリエンスを取得するには、何を追加する必要がありますか?

私は http://127.0.0.1:8888/books/search/findByTitle?title=bc&page=0

呼び出すと、私はこの応答を取得:

{ 
    "_embedded" : { 
    "books" : [ { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/4" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/4" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/5" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/5" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/6" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/6" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/7" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/7" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/8" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/8" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/9" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/9" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/10" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/10" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/11" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/11" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/12" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/12" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/13" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/13" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/14" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/14" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/15" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/15" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/16" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/16" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/17" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/17" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/18" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/18" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/19" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/19" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/20" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/20" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/21" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/21" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/22" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/22" 
     } 
     } 
    }, { 
     "title" : "bc", 
     "_links" : { 
     "self" : { 
      "href" : "http://127.0.0.1:8888/books/23" 
     }, 
     "book" : { 
      "href" : "http://127.0.0.1:8888/books/23" 
     } 
     } 
    } ] 
    }, 
    "_links" : { 
    "self" : { 
     "href" : "http://127.0.0.1:8888/books/search/findByTitle?title=bc&page=0" 
    } 
    } 
} 

答えて

1

私はあなたのリポジトリではなくListorg.springframework.data.domain.Pageを返すべきだと思います。

@RepositoryRestResource(collectionResourceRel = "books", path = "books") 
public interface BookRepository extends PagingAndSortingRepository<Book, Long> { 
    Page<Book> findByTitle(Pageable pageable, @Param("title") String title); 
} 
+0

これはページの統計情報(カウントなど)を返しましたが、HATEOASリンク(次、前、前)がまだ表示されていません。 :) – EralpB

+1

ああ、それは働いた、私は最初の試しで何かを逃した必要があります、ありがとう! – EralpB