目前我们已经公开了这样的方法
@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/