Spring Boot @DeleteMapping

Use DELETE to interact

ResponseData for custom return body {String code, String MSG, List<? > data}

PollutionData is an entity attribute and contains {String ID, String name} CodeEnum and MsgEnum for custom enumeration classes. We have defined constants in both environments: Win7 + IDEa2018.2 + JDK10.0.2 + Springboot front-end editing tool for HBuilderCopy the code

Two ways:

1.

// POST+ _method:"DELETE"+ filter (springboot does not need to be configured) var r=confirm("Method 1: Confirm deletion of this data?");
if(r){
    //var data = {_method:"DELETE", id:"456456",name:"Solicit"};
    var data = {_method:"DELETE"}; //_method:"DELETE"Yes, other attributes depend on your requirements $.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, @RequestBody PollutionData data){

    System.out.println(id);
    System.out.println(data);
    returnnew ResponseData(CodeEnum.SUCCESS.getCode(),MsgEnum.SUCCESS.getMsg(),null); } @requestBody () {// Request () {// request () {// request () {// Request () {// Request () {"Method 2: Confirm deletion of this data?");
if(r){
    var id = "123133";
    var jsonstr = { id: id,
                   name: "12345"};
    console.log(jsonstr);
    $.ajax({
        url:"http://192.168.2.116:8080/pollution/delete/" + id,
        type:"DELETE",
        contentType:"application/json",// Set the request parameter type to JSON string data: json.stringify (jsonstr),// convert the JSON object to JSON string to send dataType:"json",
        success:function(result){ alert(result.msg); }}); } /** If you do not need to pass arguments, you can omit the following items * contentType:"application/json",// Set the request parameter type to JSON string data: json.stringify (jsonstr),// convert the JSON object to 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);
}
Copy the code