简体   繁体   English

Spring Data中的Rest操作如何与Rest一起使用

[英]How does delete operation work with Rest in Spring Data

Currently we have exposed our methods like this 目前,我们已经公开了这样的方法

@RestController
@RequestMapping("/app/person")
public class PersonResource {

    @Timed
    public void delete(@PathVariable Long id) {
        log.debug("REST request to delete Person: {}", id);
        personRepository.delete(id);
    }
}

The operations of this method, in terms of input and output, are very clear to the user developer. 对于用户开发人员而言,就输入和输出而言,此方法的操作非常清楚。

This article http://spring.io/guides/gs/accessing-data-rest/ shows how to expose JPARepositories directly obviating the need of a service layer. 本文http://spring.io/guides/gs/accessing-data-rest/显示了如何直接公开JPARepositories,而无需使用服务层。

@RepositoryRestResource(collectionResourceRel="people", path="people")
public interface PersonRepository extends JpaRepository<PersonEntity, Long> {

}

It is not obvious to me how I can make a "delete operation" available with PathVariable Long id. 对我来说,如何使用PathVariable Long id使“删除操作”变得不明显。

There is an excellent article on this topic. 关于这个话题有一篇很好的文章。 https://github.com/spring-projects/spring-data-rest/wiki/Configuring-the-REST-URL-path But it actually shows how to supress export of a delete operation. https://github.com/spring-projects/spring-data-rest/wiki/Configuring-the-REST-URL-path但实际上显示了如何禁止删除操作的导出。

As documented here , Spring Data REST will expose item resources for the repository you declare. 如此处所述 ,Spring Data REST将公开您声明的存储库的项目资源。 Thus, all you need to do is discover the URI of the resource to delete and issue a DELETE request to it. 因此,您要做的就是发现要删除的资源的URI并向其发出DELETE请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM