如何在Spring Data REST中访问自定义删除操作

时间:2018-08-06 10:28:13

标签: java spring spring-security spring-data-rest

我用自定义删除方法编写了以下存储库,但我不知道如何使用REST访问它。

@RepositoryRestResource(collectionResourceRel = "carriers", path = "carriers")
public interface CarrierRepository extends PagingAndSortingRepository<CarrierEntity, Integer> {

    @PreAuthorize("hasAnyRole('CUSTOMER') && #customerId == principal.customerId")
    void deleteByIdAndCustomerId(
            @RequestParam(name = "id", defaultValue = "") @Param("id") Integer id, 
            @RequestParam(name = "customerId", defaultValue = "") @Param("customerId") Integer customerId);

}

我检查了阿尔卑斯山的概况,并说它的暴露如下:

{
    "name": "deleteByIdAndCustomerId",
    "type": "SAFE",
    "descriptors": [
        {
            "name": "id",
            "type": "SEMANTIC"
        },
        {
            "name": "customerId",
            "type": "SEMANTIC"
        }
    ]
}

0 个答案:

没有答案