简体   繁体   中英

DELTE HTTP method is not working with Spring data rest module

I have a boot app

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

I have a repository, I dont have a controller to take an advantage of Spring Data Rest Moduel. Am using SPRING DATA REST to expose HTTP methods

public interface PUCCRepository extends CrudRepository<PUCCertificate, Long> {

    @Transactional
    Long deleteByVehicleNo(@RequestParam("vehicleNo") String vehicleNo);
   
}

Now am trying to do a Delete request from UI(Angular). Its deleting the record when am doing a GET request for deleteByVechicleNo but it not deleting a record when i do DELETE request.

I attached the success and failure scenarios for your reference.

Get Request在此处输入图像描述

Delete Request在此处输入图像描述

This is because any extra methods you define on your repository are considered search operations by default (meant for read-only).

https://docs.spring.io/spring-data/rest/docs/current/reference/html/#repository-resources.search-resource

To add custom behaviour you have to implements an MVC controller annotated with @RepositoryRestController where you can define any extra operation you like.

You can read more about this approach in here: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers

You may also want to annotate your repository method with @RestResource(exported = false) so it does not get picked up as a search operation.

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