struts2 json传递对象
来源:互联网 发布:折800官网9.9包邮淘宝 编辑:程序博客网 时间:2024/06/05 06:28
今天在用struts2 异步请求从后台传一个对象到前台时遇到了一个小小的问题,现在此作一个标记,把主要的代码贴上以作备忘。
struts.xml
- <action name="getSystemContactorInfo" class="userAction" method="getSystemContactorInfo">
- <result type="json">
- <param name="includeProperties">systemContactor\.userName,systemContactor\.cellPhone,
- systemContactor\.notesMail
- </param>
- <!-- <param name="includeProperties">systemContactor</param> 这样不对-->
- <!-- <param name="includeProperties">systemContactor.*</param> 这样同样不正确-->
- </result>
- </action>
UserAction
- public String getSystemContactorInfo() {
- UserModel systemContactor = new UserModel();
- systemContactor.setUserName("张三");
- systemContactor.setCellPhone("13240151465");
- systemContactor.setNotesMail("test@126.com");
- return Action.SUCCESS;
- }
- public class UserModel{
- private String userName;
- private String cellPhone;
- private String notesMail;
- //省略get、set方法
- }
- $.ajax({
- type:'post',
- url: 'getSystemContactorInfo.action',
- dataType: 'json',
- async: true,
- success: function showContent(json) {
- var userInfo = json.systemContactor;
- $("#userName").html(userInfo.userName);
- $("#cellPhone").html(userInfo.cellPhone);
- $("#notesMail").html(userInfo.notesMail);
- }
- });
<param name="includeProperties">systemContactor.*</param>当systemContactor为list时可这样传
到现在也不是太明白当systemContactor为一个对象时为什么不能直接写在里面
0 0
- struts2 json传递对象
- struts2 json传递对象
- struts2 json传递对象
- struts2 json传递对象
- struts2+Jquery+Json异步提交(传递复杂JSON对象)
- JSON向Struts2后台传递复杂对象--传对象、集合
- JSON向Struts2后台传递复杂对象--传对象、集合
- Struts2 结合Ajax传递多个JSON对象
- ajax整合struts2,spring传递复杂json对象
- Ajax+struts2+json进行对象list前后端传递
- struts2-json 传递数据
- struts2传递对象
- Struts2 HTTP对象传递
- JSON对象传递
- Struts2 返回json对象
- Struts2返回JSON对象
- 【Struts2】(4)复杂对象传递
- Struts2 传递参数map对象
- QuickServer开发指南目录
- Ubuntu下安装JDK1.7
- C++之练习题6
- i2c驱动架构 davinc dm368 i2c驱动分析
- [LeetCode] Search Insert Position
- struts2 json传递对象
- 华为B199刷机包 官方MEUI 2.0 B190精简省电版
- div中加入span右对齐后出现换行显示两种解决思路(同行显示,一个居中,一个靠右)
- JAVA基础知识汇总
- fd_set的一些认识
- GIS开源软件集合
- UIView设置背景图片的方法
- VLC学习 第一篇安装环境
- linux指令整理(转载)