#spring-boot #spring-mvc #servlets #spring-data-jpa #spring-restcontroller
Вопрос:
this is the implementation if the Http Delete method where i'm trying to delete this object
"vente" by it's id, and as seen below the mapping is provided for the DELETE method.
@DeleteMapping(value = ConstantController.VENTE "/{venteId}")
public ResponseEntity<?> deleteVente(@PathVariable BigInteger venteId){
venteService.deleteVente(venteId);
return new ResponseEntity<Void>(HttpStatus.OK);
}
this is the uri for accessing the the service:
http://localhost:8080/stock-ws/vente/1
this what i get in the server tomcat log when i send the http request with the delete
method:
2021-10-17 22:18:29.258[0;39m [32m INFO[0;39m [35m3848[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring DispatcherServlet 'dispatcherServlet'
[2м2021-10-17 22:18:29.258[0;39m [32m ИНФОРМАЦИЯ[0;39m [35m3848[0;39m [2m— — [0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.сервлет.DispatcherServlet [0;39m [2m:[0;39m Инициализация сервлета ‘DispatcherServlet’
[2м2021-10-17 22:18:29.262[0;39m [32m ИНФОРМАЦИЯ[0;39m [35m3848[0;39m [2m— — [0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.сервлет.DispatcherServlet [0;39m [2m:[0;39m Завершена инициализация за 4 мс
[2м2021-10-17 22:18:29.289[0;39m [33m] [0;39m [35m3848[0;39m [2m— — [0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.сервлет.PageNotFound [0;39m [2m:[0;39m Нет сопоставления для УДАЛЕНИЯ /стока-ws/vente/1
couldn't spot the bug any help will be apreciated!
Ответ №1:
Может быть, вы можете попробовать это;
@RestController
@RequestMapping("/stock-ws/vente")
class TestController(){
@DeleteMapping("{venteId}")
public ResponseEntity<?> deleteVente(@PathVariable BigInteger venteId){
venteService.deleteVente(venteId);
return new ResponseEntity<Void>(HttpStatus.OK);
}
}