如何在以下代码中加入分页的功能 后端代码:@Query( "select approvalRecord from ApprovalRecord approvalRecord inner join ApprovalRecordItem approvalRecordItem on approvalRecord = approvalRecordItem.approvalRecord where approvalRecordItem.status <> 'AUDITING' and approvalRecordItem.createdBy.login = ?#{principal.username} order by approvalRecordItem.id desc" ) List<ApprovalRecord> findAuditedByCurrentUser(); @GetMapping("/approval-records/my-created") public List<ApprovalRecord> getAllCreatedApprovalRecords() { log.debug("REST request to get all getAllCreatedApprovalRecords"); return approvalRecordRepository.findByCreatedByIsCurrentUser(); } 前段代码: queryAuditing(req?: any): Observable<EntityArrayResponseType> { const options = createRequestOption(req); return this.http .get<IApprovalRecord[]>(${this.resourceUrl}/my-auditing, { params: options, observe: 'response' }) .pipe(map((res: EntityArrayResponseType) => this.convertDateArrayFromServer(res))); } loadAll(): void { this.approvalRecordService.queryAuditing().subscribe((res: HttpResponse<IApprovalRecord[]>) => { this.auditingApprovalRecords = res.body ?? []; });
时间: 2023-12-10 17:42:22 浏览: 87
实现分页功能
在前端代码中,你可以使用 ngx-pagination 库来实现分页功能。首先,你需要安装 ngx-pagination:
```
npm install ngx-pagination
```
然后,在需要使用分页的页面中引入该库:
```
import { PaginationModule } from 'ngx-pagination';
@NgModule({
imports: [PaginationModule],
...
})
export class YourModule {}
```
接着,在 HTML 中添加分页控件:
```
<div class="pagination-container">
<pagination-controls (pageChange)="pageChanged($event)"></pagination-controls>
</div>
```
其中,`pageChanged` 是当用户点击分页控件时触发的事件处理函数。你需要在组件中实现该函数,以重新加载当前页面的数据。
最后,在组件中修改 `queryAuditing` 函数,添加分页参数。例如:
```
queryAuditing(page: number, size: number): Observable<EntityArrayResponseType> {
const options = createRequestOption({ page, size });
return this.http
.get<IApprovalRecord[]>(`${this.resourceUrl}/my-auditing`, { params: options, observe: 'response' })
.pipe(map((res: EntityArrayResponseType) => this.convertDateArrayFromServer(res)));
}
```
在调用 `queryAuditing` 函数时,传入当前页码和每页数据量即可。在 `pageChanged` 函数中,调用 `queryAuditing` 并更新组件中的数据即可完成分页功能。
阅读全文