簡體   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