Note: ajax pass values to the background, you must add contentType: "application / json";
springmvc @requestBody may submit comments by json page automatically packaged as bean object, but if so how the processing
public class User{
private String id;
private int age; private String name; private Class classInfo; //getter,setter } public class ClassInfo{ private String id; private name; private User classMaster; private School school; @JsonIgnore private Set<User> teachers; //getter,setter } public class School{ private String id; private String name; //getter,setter }
I json object is a package
"classInfo":{
"id":"xxxxx",
"name":"一年级三班", //班主任 "classMaster":{ "id":"xxxx", "age":"92", "name":"班主任" }, //学校 "school":{ "id":"xxx", "name":"旭日东升小学" }, //教师集合 "teachers":[ { "id":"xxxx", "age":"92", "name":"语文老师" }, { "id":"xxxx", "age":"92", "name":"数学老师" } ] }
When data submitted: JSON.stringify (classInfo)
such class which contains the class teacher, a collection of teachers, as well as schools, the background is this
@requestMapping("xxxx")
@responseBody
public Map<String,Object> addClass(Model model, @requestBody ClassInfo classInfo){ xxxx }