spring snippet

知识点

传JSON字符串+@RequestBody接收

  • 前端

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    function icheckDelete(url){
    var parms = {
    list : array //这是个数组
    };

    $.ajax({
    dataType: "JSON",
    contentType:'application/json;charset=UTF-8',//关键是要加上这行
    traditional:true,//这使json格式的字符不会被转码
    data: JSON.stringify(parms),
    type: "DELETE",
    timeout: 20000,
    url: url,
    success : function () {
    alert("删除成功!");
    },
    error : function (data){
    alert(data.responseText);
    }
    });

    }
  • 后端

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Controller:

    @RequestMapping(value = "deleteList", method = RequestMethod.DELETE)
    @ResponseBody
    public String delete(@RequestBody DeleteListRequest request) throws WebTransException{

    /* 逻辑代码 */

    return "success";
    }