我正在使用struts2-json-plugin-2.2.3.jar
。并尝试序列化此类的filterList
属性:struts.xml
代码
<action name="jsonUserFilterListAction" class="com.my.fitnessb.actions.UserArticlesAction" method="filterList">
<result name="success" type="json">
<param name="includeProperties">filterList</param>
</result>
</action>
动作课
public class UserArticlesAction extends ActionSupport implements SessionAware, ServletRequestAware {
private List<FilterType> filterList;
HttpServletRequest request;
public String filterList() {
filterList = new ArrayList<FilterType>();
filterList.add(new FilterType(10, "Latest Articles"));
filterList.add(new FilterType(1, "Trending Articles"));
filterList.add(new FilterType(2, "Top Rated Articles"));
filterList.add(new FilterType(3, "Most Viewd Atricles"));
filterList.add(new FilterType(4, "All Atricles"));
return SUCCESS;
}
//setter & getter of filterList
}
但我无法获取FilterType类的此属性。
最佳答案
假设FilterType
中的字段分别命名为id
和desc
尝试
<param name="includeProperties">
filterList\[\d+\]\.id,
filterList\[\d+\]\.desc
</param>