JS json字符串传递后台

var topicStr=JSON.stringify(topicDTO);
	
	$.post("admin/topic/saveOrUpdateTopic.action",
			{topicStr:topicStr}
		, function(data) {
			var status = data.result;
			if (status == "success") {
				
				$.messager.alert('信息', '资讯新增成功!', 'info');
			} else {
				$.messager.alert('错误', '资讯新增失败!', 'error');
			}
		}, "json");

把topicDTO转为JSON字符串,然后传递到后台,后台使用fastJson转换

        String topicStr=this.getRequest().getParameter("topicStr");
    	TopicDTO dto=JSON.parseObject(topicStr, topicDTO.getClass());

这个的好处就是,我页面上其实是对象嵌套对象,通过parseObject方法把对象的属性和子对象的属性set进去。

topicDTO里面是含有voteDTO对象的

你可能感兴趣的:(JS json字符串传递后台)