Struts2 返回json数据的应用详解

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"}]}
 
阅读更多
文章标签: json struts null email
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Struts2 返回json数据的应用详解

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭