jackblack369
1/10/2019 - 1:45 AM

[spring annotation] #spring

[spring annotation] #spring

传JSON字符串+@RequestBody接收

  • 前端
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);
        }
    });

}
  • 后端
Controller:

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

    /* 逻辑代码 */

    return "success";
}