フロントエンドからオブジェクトを転送(オブジェクトと配列を含む)

2454 ワード

転送するコンテンツ:
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;

}