当前位置: 代码迷 >> J2EE >> org.springframework.beans.InvalidPropertyException: Invalid property
  详细解决方案

org.springframework.beans.InvalidPropertyException: Invalid property

热度:126   发布时间:2016-04-22 02:00:39.0
spring mvc 傳值 包含list的對象
model
public class RoleVO {

private String id;
private String code;
private String name;
private int roleType;
private boolean active;
private String desc;
private List<RoleMemberVO> roleMembers = new ArrayList<RoleMemberVO>();
  //getter setter
}

public class RoleMemberVO {

private String id;
private String empNo;
private String empName;
private String remark;
  //getter setter
}

js
  var roleNo = $('#roleNo').val();
var roleType = $('#roleType').val();
var roleName = $('#roleName').val();
var active = $('#roleActive').val();
var roleDesc = $('#roleDesc').val();

var rows = $('#tblRoleLine').datagrid('getRows');
var roleMembers = new Array();
for(var i=0; i<rows.length; i++) {
var member = {'empNo':rows[i].empNo,
'empName':rows[i].empName,
'remark':rows[i].mRemark};
roleMembers.push(member);
}
  $.ajax({
type:'post',
url:'save_role',  
data:{'code':roleNo,'roleType':roleType,'name':roleName,
'active':active,'desc':roleDesc,'roleMembers':roleMembers},  
dataType:'json',
success:function(data){  
$.messager.alert('提示',data.message,'info');
},
error:function(data){
$.messager.alert('提示',data.responseText,'info');
}
}); 
会报如下错误:
org.springframework.beans.InvalidPropertyException: Invalid property 'roleMembers[0][empName]' of bean class [bpm.web.vo.org.RoleVO]: Property referenced in indexed property path 'roleMembers[0][empName]' is neither an array nor a List nor a Map; returned value was [sfg]

-------------------------------
尝试用$.toJSON(roleMembers);和JSON.stringify(roleMembers);
但都报类似的错误,各位帮帮忙啊,用spring mvc 如何從頁面傳RoleVO傳到controller,
急。。。。。

------解决方案--------------------
Java code
@RequestBody
  相关解决方案