The Put and delete methods do not work when you are using spring boot to develop a restful style project.
Entity class Student
@Data Public class Student { private String ID; Private String name; Private int Age ; Private String sex; @Override public String toString () { return Tostringbuilder.reflectiontostring (this);} }
Controller
@RestController Public classGreetingcontroller {@RequestMapping (value="/demo1/student", method =requestmethod.post) Public voidaddstudent (Student Student) {System. out. println (student); System. out. println ("Add Success"); } @RequestMapping (Value="/demo1/student", method =requestmethod.put) Public voidupdatestudent (Student Student) {System. out. println (student); System. out. println ("Update Successful"); } @RequestMapping (Value="/demo1/student", method =requestmethod.get) PublicStudent Getatudentbyid (String id) {System. out. println ("the parameters received"+ID); Stuent s=NewStudent (); S.setid (" A"); S.setname ("Google"); S.setage ( A); returns; } @RequestMapping (Value="/demo1/student", method =requestmethod.delete) Public voiddelstudent (Student Student) {System. out. println (student); System. out. println ("Delete succeeded"); }}
Using the put update interface call, parameters cannot be passed past. The workaround is to add annotations before the parameters that need to be assembled @RequestBody
Modify the following:
" /demo1/student ", method = requestmethod.put) publicvoid updatestudent (@RequestBody Student Student) { System. out . println (student); System. out. println (" update succeeded "); }
Can be successfully invoked
Delete Interface modification method is the same
Using spring boot to develop a RESTful style project Put/delete method does not work