前台代码
//json对象数组
let doctur=[
{deptid: "1",ruleid: "1",userid: "1",week: "11111111100000"},
{ruleid: "3", userid: "2", deptid: "1",week: "11111100000000"}
];
$.ajax({
url : 'http://localhost:8888/scheduling/addscheduling',
data :{
'rules':JSON.stringify(rules),//将json对象数组转化为json字符串
'start':$('#logmin').val(),
'end':$('#logmax').val()
},
success : function(res){
if(res==0){
alert("排班失败")
}else{
alert("排班成功")
}
},
dataType : 'json',
type:"POST",
async : true
})
//json字符串
//[{"ruleid":"1","userid":"1","deptid":"1","week":"11111111100000"},
//{"ruleid":"3","userid":"2","deptid":"1","week":"11111100000000"}]
后台代码
@RequestMapping("addscheduling")
public int addscheduling(@RequestParam("rules") String rules){
List<Rule> list = JSON.parseArray(rules,Rule.class);
//用fastjson中的parseArray方法将字符串重新转换为List
//Rule.class项相当于List的泛型
return 1;
}