ajax内容
使用JSON.stringify()将数组转换为JSON字符串
//发送ajax将数组发送给handler$.ajax({url:"admin/batch/remove.json", //服务器接收请求的URL地址type:"post", //设置请求方式postcontentType:"application/json;charset=UTF-8", //设置请求体内容为json数据data:JSON.stringify(adminIdArray), //请求体的数据dataType:"json", //服务器端返回的数据当做json来解析success:function(response){ //服务器处理成功后执行的函数,response名称随意写,代表服务器返回的参数alert(response);}, error:function(response){ //服务器处理失败后执行的函数,response名称随意写,代表服务器返回的参数alert(response);}})
后端
传回去JSON数据用@ResponseBody,传进来JSON数据,用@RequestBody,用List接收ajax传进来的数组,
//删除//将返回值作为响应体返回,不经过视图解析器@ResponseBody@RequestMapping("admin/batch/remove")public ResultEntity<String> batchRemove(@RequestBody List<Integer> adminList) {for (Integer integer : adminList) {System.out.println(integer);}return null; }
成功获取到结果
















