Struts2 返回json数据的应用详解
2012-03-28 21:25
288 查看
Struts2返回json数据的应用详解
get方式entities对象
admins对象
<resulttype="json">
<paramname="root">entities</param>
</result>
看返回的json数据:
[{"address":null,"cellPhone":null,"email":null,"id":1,"password":"ssssssss1","realName":"sss1","role":null,"sex":null,"userName":"redarmy1"},{"address":null,"cellPhone":null,"email":null,"id":2,"password":"ssssssss2","realName":"sss2","role":null,"sex":null,"userName":"redarmy2"},{"address":null,"cellPhone":null,"email":null,"id":3,"password":"ssssssss3","realName":"sss3","role":null,"sex":null,"userName":"redarmy3"},{"address":null,"cellPhone":null,"email":null,"id":4,"password":"ssssssss4","realName":"sss4","role":null,"sex":null,"userName":"redarmy4"},{"address":null,"cellPhone":null,"email":null,"id":5,"password":"ssssssss5","realName":"sss5","role":null,"sex":null,"userName":"redarmy5"},{"address":null,"cellPhone":null,"email":null,"id":6,"password":"ssssssss6","realName":"sss6","role":null,"sex":null,"userName":"redarmy6"},{"address":null,"cellPhone":null,"email":null,"id":7,"password":"ssssssss7","realName":"sss7","role":null,"sex":null,"userName":"redarmy7"},{"address":null,"cellPhone":null,"email":null,"id":8,"password":"ssssssss8","realName":"sss8","role":null,"sex":null,"userName":"redarmy8"},{"address":null,"cellPhone":null,"email":null,"id":9,"password":"ssssssss9","realName":"sss9","role":null,"sex":null,"userName":"redarmy9"}]
get方式:entities
admins
*<resulttype="json">
*<paramname="root">entities,admins</param>
*</result>
*-------如果能写返回的结果为null
*
get方式:entities
admins
*<resulttype="json">
*<paramname="includeProperties">entities</param>
*</result>
<resulttype="json">
*
<paramname="includeProperties">entities\[\d+\].realName</param>
*</result>
<resulttype="json">
*<paramname="includeProperties">^entities\[\d+\].realName</param>
*</result>
get方式entities对象
admins对象
<resulttype="json">
<paramname="root">entities</param>
</result>
看返回的json数据:
[{"address":null,"cellPhone":null,"email":null,"id":1,"password":"ssssssss1","realName":"sss1","role":null,"sex":null,"userName":"redarmy1"},{"address":null,"cellPhone":null,"email":null,"id":2,"password":"ssssssss2","realName":"sss2","role":null,"sex":null,"userName":"redarmy2"},{"address":null,"cellPhone":null,"email":null,"id":3,"password":"ssssssss3","realName":"sss3","role":null,"sex":null,"userName":"redarmy3"},{"address":null,"cellPhone":null,"email":null,"id":4,"password":"ssssssss4","realName":"sss4","role":null,"sex":null,"userName":"redarmy4"},{"address":null,"cellPhone":null,"email":null,"id":5,"password":"ssssssss5","realName":"sss5","role":null,"sex":null,"userName":"redarmy5"},{"address":null,"cellPhone":null,"email":null,"id":6,"password":"ssssssss6","realName":"sss6","role":null,"sex":null,"userName":"redarmy6"},{"address":null,"cellPhone":null,"email":null,"id":7,"password":"ssssssss7","realName":"sss7","role":null,"sex":null,"userName":"redarmy7"},{"address":null,"cellPhone":null,"email":null,"id":8,"password":"ssssssss8","realName":"sss8","role":null,"sex":null,"userName":"redarmy8"},{"address":null,"cellPhone":null,"email":null,"id":9,"password":"ssssssss9","realName":"sss9","role":null,"sex":null,"userName":"redarmy9"}]
get方式:entities
admins
*<resulttype="json">
*<paramname="root">entities,admins</param>
*</result>
*-------如果能写返回的结果为null
*
get方式:entities
admins
*<resulttype="json">
*<paramname="includeProperties">entities</param>
*</result>
*试试上面的结果:返回的结果为[code]{"entities":[]}
<resulttype="json">
*
<paramname="includeProperties">entities\[\d+\].realName</param>
*</result>
*看结果,结果为[code]{"entities":[{"realName":"sss1"},{"realName":"sss2"},{"realName":"sss3"},{"realName":"sss4"},{"realName":"sss5"},{"realName":"sss6"},{"realName":"sss7"},{"realName":"sss8"},{"realName":"sss9"}]}
<resulttype="json">
*<paramname="includeProperties">^entities\[\d+\].realName</param>
*</result>
结果为:[code]{"entities":[{"realName":"sss1"},{"realName":"sss2"},{"realName":"sss3"},{"realName":"sss4"},{"realName":"sss5"},{"realName":"sss6"},{"realName":"sss7"},{"realName":"sss8"},{"realName":"sss9"}]}
相关文章推荐
- Struts2返回JSON数据的具体应用范例
- 深入了解Struts2返回JSON数据的原理及具体应用范例
- 转载 《Struts2返回JSON数据的具体应用范例》
- 深入了解Struts2返回JSON数据的原理及具体应用范例
- 深入了解Struts2返回JSON数据的原理及具体应用范例
- Struts2返回JSON数据的具体应用范例
- Struts2返回JSON数据的具体应用范例
- Struts2返回JSON数据的具体应用范例
- Struts2返回JSON数据的具体应用范例
- 转:Struts2返回JSON数据的具体应用范例
- Struts2返回JSON数据的具体应用范例
- Struts2返回JSON数据的具体应用范例
- Struts2返回JSON数据的具体应用范例
- 深入了解Struts2返回JSON数据的原理及具体应用范例
- 深入了解Struts2返回JSON数据的原理及具体应用范例
- Struts2返回JSON数据的具体应用范例
- 深入了解Struts2返回JSON数据的原理及具体应用范例
- Struts2返回JSON数据的具体应用范例
- (转)Struts2返回JSON数据的具体应用范例
- Java之美[从菜鸟到高手演练]之深入了解Struts2返回JSON数据的原理及具体应用范例