struts2中json应用
来源:互联网 发布:阿里云9.9半年主机 编辑:程序博客网 时间:2024/06/01 20:12
1.导包struts2-json-plugin-2.1.8.1.jar
2.(1)struts.xml
<package name="dang-default" extends="json-default" namespace="/"> <include file="config/struts/struts-user.xml" /></package>(2)struts-user.xml
<package name="user" extends="dang-default" namespace="/user"><action name="userAction_*" class="com.tarena.dang.web.action.UserAction" method="{1}">.............</action></package>3.具体的语法在代码中体会,说再多也不如实践
(1)
<result name="displayVerifyCode" type="json"> <param name="includeProperties">user\.verifyCode</param></result>
结果
{"user":{"verifyCode":"6de5fe9c67c140469310ee1f54e56a14-79"}}
在js中用jquery ajax处理返回来的json字符串 data.user.verifyCode (前提是dataType是json,data为success()函数的参数)
如果要访问user的全部属性,在struts.xml中
<result name="displayVerifyCode" type="json"> <param name="includeProperties">user.*</param></result>
结果
{"user":{"email":"1112223@qq.com","emailVerify":0,"id":0,"lastIP":null,"lastLogin":0,"nickname":null,"password":null,"verifyCode":"6de5fe9c67c140469310ee1f54e56a14-79"}}
如果访问的的是一个List类型的.List<User> userList = new ArrayList<User>();
要返回userList中所有信息
<result name="displayVerifyCode" type="json"> <param name="includeProperties">userList.*</param></result>
结果
{"userList":[{"email":"865631572@qq.com","emailVerify":0,"id":1,"lastIP":null,"lastLogin":0,"nickname":"李勇","password":"1234","verifyCode":null},{"email":"1091574864@qq.com","emailVerify":0,"id":2,"lastIP":null,"lastLogin":0,"nickname":"张超","password":"1234","verifyCode":null}]}
如果要返回userList中所有user对象的所有email
<result name="displayVerifyCode" type="json"> <param name="includeProperties">userList\[\d+\]\.email</param></result>
结果
{"userList":[{"email":"865631572@qq.com"},{"email":"1091574864@qq.com"}]}
(2)根对象只包含user
<result name="displayVerifyCode" type="json"> <param name="root">user</param> </result>
结果
{"email":"1112223@qq.com","emailVerify":0,"id":0,"lastIP":null,"lastLogin":0,"nickname":null,"password":null,"verifyCode":"6de5fe9c67c140469310ee1f54e56a14-79"}
在js中 data.verifyCode 就可以得到,前面不需要加user
- struts2中json应用
- JSON应用-Struts2
- Struts2中使用JSON
- Struts2中json使用
- struts2中配置json
- Struts2中操作JSON
- struts2项目搭建,json应用
- struts2-ajax-json应用实例
- [Struts2应用开发] JSON的应用
- struts2 中json使用体验
- struts2 中json使用体验
- 在struts2中使用JSON
- Struts2中Action返回Json
- struts2中json的使用
- Struts2中json的使用
- struts2中ActionContext应用
- struts2中jason应用
- struts2中应用jason
- c# 用反射实现winform界面动态存储理论知识
- 项目管理 笔记之三 —— 项目综合管理
- NetBIOS、Samba、CIFS概念及相关
- linux-UDP
- java编码 乱码解析
- struts2中json应用
- 托福考试总结——南京师范大学考点
- C语言函数:toupper
- c++ stl library 学习(4)
- WebView总结
- Android Lint Checks
- Flex走出低谷的关键: 打破Flex固有的定义
- C# 中利用 DirectSound 录音
- HTML <base> 标签的 href 属性