Json-lib通过JsonConfig类设置不需要转换属性
程序员文章站
2022-07-12 15:53:13
...
PageBean的各项属性
public class PageBean<T> {
/*当前显示页数*/
private int currentPage;
/*每页显示的记录数*/
private int pageSize;
/*查询条件*/
private DetachedCriteria detachedCriteria;
/*总记录数*/
private int total;
/*当前页需要返回的数据集合*/
private List<T> rows;
}
通过JsonConfig 的setExcludes设置不需要转换的属性
public String pageQuery() throws Exception{
PageBean<BcStaff> pageBean = new PageBean<>();
pageBean.setCurrentPage(page);
pageBean.setPageSize(rows);
//创建离线查询对象
pageBean.setDetachedCriteria(DetachedCriteria.forClass(BcStaff.class));
staffService.pageQuery(pageBean);
JsonConfig config = new JsonConfig();
config.setExcludes(new String[]{"currentPage","pageSize","detachedCriteria"});
String json = JSONObject.fromObject(pageBean,config).toString();
ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");
ServletActionContext.getResponse().getWriter().write(json);
return NONE;
}
上一篇: QML键盘事件