赞
踩
@RequestBody这个注解将前台传来的json数据转化为对象类型
**eg1:**第一种前台传数组
注意:
通过ajax把json数组传到后台需要用@RequestBody接收
1、把数据封装成json数组
2、把数据通过data:JSON.stringify(ids),传参
3、 headers: {
‘Content-Type’: ‘application/json’
},
设置ajax发送方式为json
4、后台通过@RequestBody Integer[] ids 接收
var data = checkStatus.data; var ids = []; $.each(data, function (index, item) { ids.push(item.emp_id); }) $.ajax({ // 设置请求为json 后台就ok 参数就能@RequestBody 对上 headers: { 'Content-Type': 'application/json' }, url: "/emp/deleteAll", data:JSON.stringify(ids), // data: JSON.stringify(ids), dataType: "json", type: "post", //通过ajax把数组传到后台 // traditional: true, success: function (dataInfo) { if (dataInfo.code == "200") { layer.msg(dataInfo.msg); //重载表格 tablei.reload(); } else { layer.msg(dataInfo.msg); } } }) break;
前台通过ajax发送请求,前台ajax添加,后台就不用加**@RequestBody**这个注解
//通过ajax把数组传到后台
traditional: true,
**eg2:**前台传来的json数据传到后台
http://127.0.0.1:8080/startCntr?ids=1&ids=2
http://127.0.0.1:8080/startCntr?ids=1,2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。