日期:2014-05-16  浏览次数:20704 次

spring3 mvc 接受json格式数据是转换报错.用注解方式@RequestBody
spring3 mvc 接受json格式数据是转换报错.用注解方式@RequestBody 将接受的json数据自动转换为java实体对象报错,转换不了. 点击新增 按钮 报错
org.codehaus.jackson.map.JsonMappingException: Unrecognized field "user" (Class com.springmvcext.pojo.Users), not marked as ignorable.

代码如下:




@Controller
@RequestMapping("/springMvcExt")
public class UserController {
private Logger logger = org.slf4j.LoggerFactory.getLogger(UserController.class);



@RequestMapping(value="/userManage",method=RequestMethod.POST)
@ResponseBody

public Map<String, Object> add(@RequestBody Users user) {  
 
Map<String, Object> modelMap = new HashMap<String, Object>();
 
logger.info(" addUser: add ");

System.out.println("Users id is :  "+user.getId());
System.out.println("Users name is : "+user.getUsername());
System.out.println("Users password is :"+user.getPassword());

modelMap.put("success", true);
return modelMap;
}
}

js 代码 ==========
Ext.onReady(function() {

// demoStroe
var demoStore = new Ext.data.JsonStore({
add : true,
remoteSort : true,
restful : true,
autoLoad : true,
idProperty : 'id',
root : 'user',
totalProperty : 'total',
fields : ['id', 'username', 'password'],
proxy : new Ext.data.HttpProxy({
restful : true,
url : 'springMvcExt/userManage'
// url : 'userManage'
}),
writer : new Ext.data.JsonWriter({
encode : false,
writeAllFields : true
}),

onCreate : function(values) {
var a = new this.recordType(values);
this.insert(0, a);
}

});

var demoGrid = new Ext.grid.GridPanel({

title : '测试demo',
id : 'demoGrid',
height : 150,
width : 400,
store : demoStore,
trackMouseOver : false,
disableSelection : true,
loadMask : true,
columns : [{
header : '编号',
dataIndex : 'id',
// hidden : true,
sortable : true
}, {
header : '名称',
dataIndex : 'username'
}, {
header : '密码',
dataIndex : 'password'
}],
viewConfig : {
forceFit : true
},
bbar : new Ext.PagingToolbar({
pageSize : 5,
store : demoStore,
displayInfo : true,
displayMsg : 'Displaying topics {0} - {1} of {2}',
emptyMsg : "No topics to display"
}),
sm : new Ext.grid.RowSelectionModel({
singleSelect : true,
listeners : {
rowselect : function(sm, row, rec) {
Ext.getCmp("d