spring - Spring Data 中的删除操作如何与 Rest 配合使用

标签 spring spring-data crud spring-data-rest http-delete

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

@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 但它实际上展示了如何抑制删除操作的导出。

最佳答案

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

关于spring - Spring Data 中的删除操作如何与 Rest 配合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27663028/

相关文章:

php - 以编程方式设置 WooCommerce 用户账单和发货国家/地区

java - Spring安全5/Spring Boot 2.2 : No AuthenticationProvider found for org. springframework.security.authentication.UsernamePasswordAuthenticationToken

java - 更改 Spring openapi-generator-maven-plugin 生成的接口(interface)的返回类型

java - Spring-Data 从 Controller 调用实体上的保存

java - 通过 Spring Boot 实体注释在 mysql 中创建了两个名为 blog 和 blog_seq 的表

java - 在 crud Play 1.2.4 中使用复合键路由到默认编辑模板

php - 针对 1000000 多行优化此查询

java - Setter 注入(inject)不适用于 Spring 的工厂方法注入(inject)

java - 如何向ajax请求添加请求参数,以获取从jSON初始化并由Spring映射的jQuery数据表

spring - 如何在Spring中为多个数据源设置liquibase?