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 参数。 

原文地址:https://www.cnblogs.com/sharpest/p/9798605.html