关于前台传json对象数组springMVC如何接取

前台传值是需要现将数组转换成json字符串然后在后台处理用数组j接取

前台代码
//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 list = JSON.parseArray(rules,Rule.class);
        //用fastjson中的parseArray方法将字符串重新转换为List
        //Rule.class项相当于List的泛型
       return 1;
    }

你可能感兴趣的:(关于前台传json对象数组springMVC如何接取)