jpa查询中的分页给出了页面中错误的元素数



我得到了错误的项目数量(与我传递的页面大小不同(。代码如下,

Query query = entityManager.createQuery("SELECT new com.one97.one97pay.web.dto.CustomerReportResponseDTO(cw.walletId, cw.balance, cw.isEnabled,ca.isEnabled,ca.accountLockType,ck.isEnabled AS kycStatus,cp.mobile,cp.residentId,cp.ridExpiryDate, ck.kycStatus,ck.kycType,ca.createdOn "
+ ",TRIM(UPPER(CONCAT (cp.firstName,CASE WHEN cp.middelName is NULL THEN '' ELSE CONCAT(' ', cp.middelName) END,CASE WHEN cp.lastName is NULL THEN '' ELSE CONCAT(' ', cp.lastName) END ))), ck.creationDateTime)"
+ " FROM CustomerProfile AS cp JOIN CustomerAuthModel AS ca ON cp.customerId=ca.customerId "
+ " JOIN CustomerWalletModel AS cw ON cp.customerId = cw.customerId "
+ " JOIN CustomerKycModel AS ck ON ck.customerId = cw.customerId"
+ " ORDER BY ck.creationDateTime DESC");
int pageSize = requestDto.getPageSize();
int pageNumber = requestDto.getPageNum();
query.setFirstResult((pageNumber-1) * pageSize); 
query.setMaxResults(pageSize);
List <CustomerReportResponseDTO> customerReportLst = query.getResultList();

我已经检查了另一个没有分页的api,结果的数量是100+,但当我将页码作为1,页面大小为10时,我得到了8个元素作为回报。我做错了什么,或者有其他方法吗?

通过查看您的代码,我认为*pageSize不会出现在query.setFirstResult中,因为我认为您正在将页码保存在setFirstResults中,因此根据该逻辑编写此query.setFirstResult(pageNumber-1);

相关内容

最新更新