gpt4 book ai didi

java - Spring Data Rest - 如何从页面中删除元素?

转载 作者:行者123 更新时间:2023-11-29 08:27:32 25 4
gpt4 key购买 nike

我的项目中有以下 REST Controller 方法

@RequestMapping(method = GET, value = "applications", produces = {MediaType.APPLICATION_JSON_VALUE})
public @ResponseBody
ResponseEntity<?> getApplications(@QuerydslPredicate(root = Application.class) Predicate predicate,
PersistentEntityResourceAssembler resourceAssembler, Pageable page) {

Page<ApplicationProjection> applications = appRepo.findAll(predicate, page).
map(item -> projectionFactory.createProjection(ApplicationProjection.class, item));

return new ResponseEntity<>(pagedResourcesAssembler.toResource(applications), HttpStatus.OK);

}

现在我想根据条件删除页面的一些元素。如何在 Spring Data Rest 中实现?

最佳答案

您不能直接从页面中删除元素。你可以做的是,从页面中获取内容,这将是一个列表,然后根据你的条件从列表中删除元素,然后创建一个具有修改后的列表和大小的新页面。

Page<ApplicationProjection> applications = appRepo.findAll(predicate, page).
map(item -> projectionFactory.createProjection(ApplicationProjection.class, item));

List<ApplicationProjection> appList = applications.getContent();
// logic to remove the elements as per your condition modifiedAppList
// create a new Page with the modified list and size
Page<ApplicationProjection> newApplicationsPage = new PageImpl<>(modifiedAppList, PageRequest.of(pageNo, pageSize),modifiedAppList.size());

关于java - Spring Data Rest - 如何从页面中删除元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51401929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com