Using spring boot to develop a RESTful style project Put/delete method does not work

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.