使用 PagingAndSortingRepository 內(nèi)容返回 {} 和來自頁面 url 參數(shù)的正確內(nèi)容數(shù)。示例:我的表有 20 行,在 url 中有一個 put ?page=0&size=10。郵遞員返回時關(guān)鍵內(nèi)容返回 "content": [ {}, {}, {}, {}, {}, {}, {}, {}, {}, {} ]調(diào)試請求并返回它有值。但是不顯示。不知道為什么。我的倉庫public interface LocalUtilRepository extends PagingAndSortingRepository<LocalUtilModel, Integer> { Page<LocalUtilModel> findAll(Pageable pageable);}春季啟動版本<artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> 請求的結(jié)果{ "content": [ {}, {}, {}, {}, {}, {}, {}, {}, {}, {} ], "pageable": { "sort": { "sorted": false, "unsorted": true, "empty": true }, "offset": 0, "pageNumber": 0, "pageSize": 10, "unpaged": false, "paged": true }, "totalPages": 2, "totalElements": 11, "last": false, "size": 10, "number": 0, "sort": { "sorted": false, "unsorted": true, "empty": true }, "numberOfElements": 10, "first": true, "empty": false}我的模型 @Entity(name = "EXPLOCALUTIL")public class LocalUtilModel { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @NotNull @Size(min = 5, max = 255) @Column(name = "DESCLOCALUTIL") private String descLocalUtil; @Column(name = "COORD") private String coordenada; private String referencia; @NotNull @Column(name = "IDEXPFEIRA") private Integer idExpFeira;}
2 回答

繁花如伊
TA貢獻(xiàn)2012條經(jīng)驗 獲得超12個贊
根據(jù)您的 JSON 響應(yīng),它顯示為"offset":0
.
嘗試在您的存儲庫可分頁參數(shù)中傳遞它。
PageRequest.of(0, 10)
這里 0 是頁碼,10 是偏移量。
公式定義:
int start = pageNumber * offset + 1; int end = start+offset.
所以在我們的場景中,開始為 1,結(jié)束為 10。這將獲取前 10 個回報。
ResponseEntity.ok().body( localUtilRepository.findAll(PageRequest.of(0, 10))
只需在第一個參數(shù)中傳遞您的頁面,在第二個參數(shù)中傳遞大小。
添加回答
舉報
0/150
提交
取消