简体   繁体   中英

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.

@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.

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.

As documented here , Spring Data REST will expose item resources for the repository you declare. Thus, all you need to do is discover the URI of the resource to delete and issue a DELETE request to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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