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