从前端传送一个对象(包含一个对象和一个数组)

需要传送的内容:

var json = {

    "datavConfig": {

        screenHeight: 768,

        screenWidth: 1366,

        viewName: "测试",

        background: "canvas.png",

        fontColor: "#FFFFFF"

    },

    "datavChartDataList": [

        {

            "bgColor": "red",

            "chartHeight": "10",

            "chartWidth": "20",

            "positionX": "11",

            "positionY": "22",

            "widgetId": "a123",

            "chartStyle": "pic1.jpg",

            "chartType": "bar"

        }

    ]

}

前端的ajax操作:

$.ajax({

    url: "/cboard/dashboard/saveNewDatav.do",

    data: JSON.stringify(json),

    type: "POST",

    contentType: 'application/json;charset=utf-8',

    success: success,

    error: error,

})

后台用于接受参数的实体类:

public class ViewDashboardDatav implements Serializable{

    private DatavConfig datavConfig;

    private List datavChartDataList;

  ...

  get 和 set 方法

  ...

}



public class DatavConfig {

    private String viewName;

    private String screenWidth;

    private String screenHeight;

    private String fontColor;

    private String background;

    private Date createTime;

    private String createUser;

    private Date updateTime;

    private String updateUser;

    ...

    get 和 set 方法

    ...

}



public class DatavChartData {

    private String bgColor;

    private String chartHeight;

    private String chartWidth;

    private String positionX;

    private String positionY;

    private String widgetId;

    private String chartStyle;

    private String chartType;

    private String createUser;

    private Date createDate;

    private String updateUser;

    private Date updateDate;

    ...

    get 和 set 方法

    ...

}

后台数据接收操作:

@RequestMapping(value = "/saveNewDatav",consumes = "application/json;charset=utf-8")

@ResposeBody

public ServiceStatus saveNewDatav(@RequestBody ViewDashboardDatav viewDashboardDatav){

    System.out.println(viewDashboardDatav.getDatavConfig());

    System.out.println(viewDashboardDatav.getDatavChartDataList());

    return null;

}

 

你可能感兴趣的:(从前端传送一个对象(包含一个对象和一个数组))