关闭

Struts2 返回json数据的应用详解

标签: jsonstrutsnullemail
1624人阅读 评论(0) 收藏 举报

Struts2 返回json数据的应用详解

get方式 entities对象  admins 对象

   <result type="json">

 <param name="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

        *      <result type="json">

        *        <param name="root">entities,admins</param>

        *     </result>

        *  -------如果能写返回的结果为null

          

                *       

 

 

 

get方式:entities  admins

        *      <result type="json">

        *        <param name="includeProperties">entities</param>

        *     </result>

                *     试试上面的结果:返回的结果为{"entities":[]}

 

 

 

<result type="json">

        *        <param name="includeProperties">entities\[\d+\].realName</param>

        *     </result>

                *     看结果,结果为{"entities":[{"realName":"sss1"},{"realName":"sss2"},{"realName":"sss3"},{"realName":"sss4"},{"realName":"sss5"},{"realName":"sss6"},{"realName":"sss7"},{"realName":"sss8"},{"realName":"sss9"}]}

<result type="json">

        *        <param name="includeProperties">^entities\[\d+\].realName</param>

        *     </result>

结果为:{"entities":[{"realName":"sss1"},{"realName":"sss2"},{"realName":"sss3"},{"realName":"sss4"},{"realName":"sss5"},{"realName":"sss6"},{"realName":"sss7"},{"realName":"sss8"},{"realName":"sss9"}]}
 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:453425次
    • 积分:5398
    • 等级:
    • 排名:第4955名
    • 原创:165篇
    • 转载:6篇
    • 译文:0篇
    • 评论:24条
    最新评论