3

I am trying to update an entity from my Oracle database using a Spring RestController. Whether I use PostMapping or PutMapping on my controller method, the effect is the same on the entity, only the field I want to update gets updated and everything is fine. What is the real difference between the two request methods? Is it only for a clearer description on the controller method?

Update : it seems even if I use a GetMapping, my entity updates correctly. I am really starting to think that the request is getting handled in the Service layer and the request annotation is only for a clearer view on the controller method, but I could be wrong. Really curious for an explanation. Thank you!

Thank you!

Ahmad Bayan
  • 67
  • 1
  • 2
  • 10
  • 2
    One allows accepting HTTP POST request, the other one allows accepting HTTP PUT requests. None of them has anything to do with how entities are saved. https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/PostMapping.html – JB Nizet Oct 19 '19 at 06:47
  • this makes sense – Ahmad Bayan Oct 19 '19 at 06:48
  • 1
    Possible duplicate of [PUT vs. POST in REST](https://stackoverflow.com/questions/630453/put-vs-post-in-rest) – ivanjermakov Oct 19 '19 at 07:48

1 Answers1

3

I guess you are looking for the Post vs PUT of REST. Check this one.

PUT vs. POST in REST

Even you can do the same operation in the backend for PUT and POST, but there is some routines people are following.

donglinjy
  • 1,104
  • 6
  • 14