小编K K*_*mar的帖子

如何使用 REST API 删除多条记录

我是Springboot的新手,我开发了通过ID删除记录的资源,现在我喜欢删除选定的多条记录。示例:我喜欢在单个请求中删除 10 条记录中的 3 条记录

控制器类:

 @ApiHeader(
            apiOperation = "delete a Content Manage by id",
            apiOperationNotes = "delete a Content Manage by id"
    )
    @PostMapping(value = UriConstants.CONTENT_MANAGE_DELETE)
    @ResponseStatus(HttpStatus.OK)
    public void deleteContentManage(@PathVariable("content_manage_id") int contentmanageId) {
        contentManageService.deleteContentManage(contentmanageId);
    }
Run Code Online (Sandbox Code Playgroud)

服务等级:

  @Transactional(rollbackFor = Exception.class)
    public void deleteContentManage(int contentmanageId) {
        Optional<UserContentManage> optional = userContentManageRepository.findById(contentmanageId);
        if(!optional.isPresent()){
            log.error("Exception occurs while not found content manage ({}) in deletion. ", contentmanageId);
            throw new GenericBadException(StaffNotificationExceptionEnum.CONTENT_MANAGE_NOT_FOUND_EXCEPTION);
        }
        userContentManageRepository.deleteById(contentmanageId);
    }
Run Code Online (Sandbox Code Playgroud)

JPA类:

public interface UserContentManageRepository extends JpaRepository<UserContentManage, Integer> {
}
Run Code Online (Sandbox Code Playgroud)

请建议我如何删除选定的多条记录。

arrays collections rest jpa spring-boot

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

arrays ×1

collections ×1

jpa ×1

rest ×1

spring-boot ×1