2
@RequestMapping(value ="/user_cart/remove/", method = {RequestMethod.GET,RequestMethod.DELETE})
public void removeData(Long id) {
    userReqDetailService.removeByID(id);

}

When i try to use like this if always return to another url (http://localhost:8082/user_cart/remove/?id=163) and error massage to spring ( template: "class path resource [templates/user_cart/remove.html]") )

I just want to delete data by id and don't want to return to another page url

Mango Play
  • 81
  • 5
  • Using GET as a delete is a very b ad idea... If this is a public facing website, one scan by google and poof... But this is a regular method in an `@Controller` use an `@RestController` or place an `@ResponseBody` on the method to prevent a page from rendering. – M. Deinum Mar 16 '23 at 09:13
  • But When I use @ResponseBody is return error the same brother ...? and how can i change i just need only delete dont' need to return to another page brother ? – Mango Play Mar 16 '23 at 09:19
  • I doubt it is doing the same. It won't forward to a new page it will just return a HTTP 200. Also if you navigate to the URL (which is what you seem to be doing) you will obviously go to this page. – M. Deinum Mar 16 '23 at 09:43
  • this one I use with controller for btn_delete on Thymleaf brother – Mango Play Mar 16 '23 at 09:54
  • Firstly I'm not your brother so stop calling me that, next I have now idea what you are using it with in thymeleaf. I suspect a form submit which will **always** take you there. If you don't you need to do an ajax post of the form instead of a regular form. – M. Deinum Mar 16 '23 at 10:00

1 Answers1

0

Add @ResponseBody on method removeData.

@RequestMapping(value ="/user_cart/remove/", method = {RequestMethod.GET,RequestMethod.DELETE})
@ResponseBody
public void removeData(Long id) {...}
Anonymus
  • 138
  • 1
  • 2
  • @RequestMapping(value ="/user_cart/remove/", method = {RequestMethod.GET,RequestMethod.DELETE}) @ResponseBody public void removeData(Long id) { userReqDetailService.removeByID(id); } but i still return ot another URL – Mango Play Mar 16 '23 at 09:20
  • http://localhost:8082/user_cart/remove/?id=161 when i click btn delete is return to this URL – Mango Play Mar 16 '23 at 09:24