Struts2 中 result type=”json” 的參數解釋


轉自:http://wangquanhpu.iteye.com/blog/1461750

1, ignoreHierarchy 參數:表示是否忽略等級,也就是繼承關系,比如:TestAction 繼承於 BaseAction,那么 TestAction 中返回的 json 字符串默認是不會包含父類 BaseAction 的屬性值,ignoreHierarchy 值默認為 true,設置為 false 后會將父類和子類的屬性一起返回。 

Java代碼   收藏代碼
  1. <result type=”json”>  
  2.     <paramname=”ignoreHierarchy”>false</param>  
  3. </result>  



2, excludeNullProperties 參數:表示是否去掉空值,默認值是 false,如果設置為 true 會自動將為空的值過濾,只輸出不為空的值。 

Java代碼   收藏代碼
  1. <result ype=”json”>  
  2.      <paramname=”excludeNullProperties”>true</param>  
  3. </result>  



3, root 參數:從返回結果中根據 ognl 表達式取出你需要輸出的結果。 
只輸出 person 對象的 name 屬性值,配置如下: 

Java代碼   收藏代碼
  1. <result type=”json”>  
  2.      <param name=”root”>person.name</param>  
  3. </result>  



4, includeProperties 參數:輸出結果中需要包含的屬性值,這里正則表達式和屬性名匹配,可以用 “,” 分割填充多個正則表達式。 

Java代碼   收藏代碼
  1. <result type=”json”>  
  2.    <param name=”includeProperties”>person.*, person\.name</param>  
  3. </result>  



5, excludeProperties 參數:輸出結果需要剔除的屬性值,也支持正則表達式匹配屬性名,可以用 “,” 分割填充多個正則表達式,類同 includeProperties 參數。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM