Struts2+JSON+jQuery兑现异步交互数据时选择要序列化的属性(二使用XML配置方式)

Struts2+JSON+jQuery实现异步交互数据时选择要序列化的属性(二使用XML配置方式)

转载自:http://zyw090111.iteye.com/blog/724574

Struts2+JSON+jQuery实现异步交互数据时选择要序列化的属性(二使用XML配置方式)

 

 

只需在XML配置就可以了,配置方式是: 

Xml代码   Struts2+JSON+jQuery兑现异步交互数据时选择要序列化的属性(二使用XML配置方式)
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">  
  3. <struts>  
  4.     <package name="jsons" extends="json-default" namespace="/">  
  5.         <action name="getJSON" class="test.json.Users">  
  6.             <result name="success" type="json">  
  7.                 <!-- excludeProperties表示不包含的属性(可以使用正则表达式匹配) -->  
  8.                 <param name="excludeProperties">  
  9.                     id,userName  
  10.                 </param>  
  11.                 <!-- includeProperties表示包含序列化的属性(可以使用正则表达式匹配) -->  
  12.                 <param name="includeProperties">  
  13.                     pwd,address  
  14.                 </param>  
  15.                 <!-- 这样序列化工作就从birthday开始了  
  16.                 <param name="root">  
  17.                     birthday  
  18.                 </param> -->  
  19.             </result>  
  20.         </action>  
  21.     </package>  
  22. </struts>      


默认情况下Struts2插件的序列化是从Action开始的如果需要序列化从指定的方式开始请使用: 

Xml代码   Struts2+JSON+jQuery兑现异步交互数据时选择要序列化的属性(二使用XML配置方式)
  1. <!-- 这样序列化工作就从birthday开始了-->  
  2.                 <param name="root">  
  3.                     birthday  
  4.                 </param>