我创建了一个对象并添加到 Jquery 中的数组中,如下所示
function CharacterData(name,value,type) {
this.name = name;
this.value = value;
this.type = type;
}
var characters = new Array();
characters[0]=new CharacterData("0","1","2");
characters[1]=new CharacterData("0","1","2");
$.ajax({
type: "POST",
url: "xxyyzz.action",
data: {
characters:characters
},
success:function(response) {
alert("GOOD");
}
});
现在我需要将此值传递给我的 Spring MVC 控制器,如下所示
@ResponseBody
@RequestMapping(value = "xxyyzz.action", method = {RequestMethod.POST})
public MyClass getxxyyzzPage(
final CharacterDataList characters) {
return null;
}
POJO如下
public class CharacterDataList {
private List<CharacterData> characterData;
public List<CharacterData> getCharacterData() {
return characterData;
}
public void setCharacterData(
final List<CharacterData> characterData) {
this.characterData = characterData;
}
}
下一个
public class CharacterData {
private String name, value, type;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(final String value) {
this.value = value;
}
public String getType() {
return type;
}
public void setType(final String type) {
this.type = type;
}
}
但在控制器中,我得到“characters!=null”但“characters.characterData=null”。请让我知道如何传递这些值?