繁体   English   中英

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

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

目前,我们已经公开了这样的方法

@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);
    }
}

对于用户开发人员而言,就输入和输出而言,此方法的操作非常清楚。

本文http://spring.io/guides/gs/accessing-data-rest/显示了如何直接公开JPARepositories,而无需使用服务层。

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

}

对我来说,如何使用PathVariable Long id使“删除操作”变得不明显。

关于这个话题有一篇很好的文章。 https://github.com/spring-projects/spring-data-rest/wiki/Configuring-the-REST-URL-path但实际上显示了如何禁止删除操作的导出。

如此处所述 ,Spring Data REST将公开您声明的存储库的项目资源。 因此,您要做的就是发现要删除的资源的URI并向其发出DELETE请求。

暂无
暂无

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

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