亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

分頁內容返回空

分頁內容返回空

一只名叫tom的貓 2023-04-26 10:47:36
使用 PagingAndSortingRepository 內容返回 {} 和來自頁面 url 參數的正確內容數。示例:我的表有 20 行,在 url 中有一個 put ?page=0&size=10。郵遞員返回時關鍵內容返回    "content": [        {},        {},        {},        {},        {},        {},        {},        {},        {},        {}    ]調試請求并返回它有值。但是不顯示。不知道為什么。我的倉庫public interface LocalUtilRepository extends PagingAndSortingRepository<LocalUtilModel, Integer> {    Page<LocalUtilModel> findAll(Pageable pageable);}春季啟動版本<artifactId>spring-boot-starter-parent</artifactId>        <version>2.1.6.RELEASE</version> 請求的結果{    "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貢獻2012條經驗 獲得超12個贊

根據您的 JSON 響應,它顯示為"offset":0.

嘗試在您的存儲庫可分頁參數中傳遞它。

PageRequest.of(0, 10)這里 0 是頁碼,10 是偏移量。

公式定義:

int start = pageNumber * offset + 1;
int end = start+offset.

所以在我們的場景中,開始為 1,結束為 10。這將獲取前 10 個回報。

ResponseEntity.ok().body( localUtilRepository.findAll(PageRequest.of(0, 10))

只需在第一個參數中傳遞您的頁面,在第二個參數中傳遞大小。


查看完整回答
反對 回復 2023-04-26
?
侃侃爾雅

TA貢獻1801條經驗 獲得超16個贊

我不得不@Data在模型類中注釋 with 因為我正在使用lombok.



查看完整回答
反對 回復 2023-04-26
  • 2 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號