ajax 数组 传参

需要添加 traditional:true,//传数组 防止深度序列化 这句,否则String[] areaIds 接收一直是NULL。
js:
function showLine(chartId,type,areaIds) {
    //console.log("showLine"+areaIds);
    var myChart = echarts.init(document.getElementById(chartId));
    $.ajax({
        url: basePath + '/getCompareLine',
        data:{
            type : type,
            begDate : begDate,
            endDate : endDate,
            areaIds : areaIds
        },
        traditional:true,//传数组 防止深度序列化
        type: 'post',
        dataType: 'json',
        success: function(data) {
            console.log(data);
            myChart.setOption(data);
        }
    });
}
controller层:
@RequestMapping(value = "/getCompareLine",produces="text/html;charset=UTF-8")
@ResponseBody
public String getCompareLine(
        @RequestParam(name = "type", required = false) String type,
        @RequestParam(name = "begDate", required = false) String begDate,
        @RequestParam(name = "endDate", required = false) String endDate,
        @RequestParam(name = "areaIds", required = false) String[] areaIds) {

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页