Spring Boot @DeleteMapping

Source: Internet
Author: User

Interactive description Using Delete: ResponseData is a custom return body {string code, string msg, list<?> data} pollutiondata as an entity attribute partial package Contains {string id, string name} CodeEnum, Msgenum is a custom enumeration class, defines some constants two ways have been tested environment: WIN7+IDEA2018.2+JDK10. 0.2+springboot front-end editing tools for Hbuilder two ways: 1,
//method One uses post+ _method: "DELETE" + filter (Springboot does not need us to configure)//the Transfer object here is JSON object, the background directly acceptsvarR=confirm ("Method one: Confirm the deletion of this data?") ");if(r) {//var data = {_method: "DELETE", ID: "456456", Name: "Solicitation"};    vardata = {_method: "DELETE"};//_method: "DELETE" must, other properties to see your needs$.ajax ({URL:"http://192.168.2.116:8080/pollution/delete/1786vdsds863", type:"POST", Data:data, DataType:"JSON", Success:function(Result) {alert (result.msg);        }    }); }
@DeleteMapping ("/pollution/delete/{id}") public responsedata Deletepollutionbyid (@PathVariable ( "id") String ID, pollutiondata data) {    System.out.println (ID);    SYSTEM.OUT.PRINTLN (data);     return New ResponseData (CodeEnum.SUCCESS.getCode (), MSGENUM.SUCCESS.GETMSG (),null);}

2.

//method Two uses the delete request//This is the Transfer object. Use @requestbody annotations to parse the string and map the string to the corresponding entity in the background of the JSON stringvarR=confirm ("Method two: Confirm the deletion of this data?") ");if(r) {varid = "123133"; varJsonstr ={id:id, Name:"12345"};    Console.log (JSONSTR); $.ajax ({URL:"http://192.168.2.116:8080/pollution/delete/" +ID, type:"DELETE", ContentType:"Application/json",//Set request parameter type to JSON stringData:JSON.stringify (JSONSTR),//convert a JSON object to a JSON string to sendDataType: "JSON", Success:function(Result) {alert (result.msg);        }    }); }/** If you do not need to pass parameters, you can not write the following items * ContentType: "Application/json",//Set request parameter type is JSON string data:JSON.stringify (JSONSTR),// Converts a JSON object into a JSON string to send DataType: "JSON",*/
@DeleteMapping ("/pollution/delete/{id}") public responsedata Deletepollutionbyid (@PathVariable ( "id") String ID, @RequestBody pollutiondata data) {    System.out.println (ID);    SYSTEM.OUT.PRINTLN (data);     return New ResponseData (CodeEnum.SUCCESS.getCode (), MSGENUM.SUCCESS.GETMSG (),null);}

Ref: 78972644

Spring Boot @DeleteMapping

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.