/** * @Author:txp * @Description:过滤掉不需要返回的字段 * @Param: [src, clazz, args]` * @Data: 2017/10/10 9:10 * @return java.lang.String */ public static String filterFieldsJson(Object src, Class<?> clazz, String... args) { SimplePropertyPreFilter filter = new SimplePropertyPreFilter(clazz, args); return JSON.toJSONString(src, filter); }
Controller:
/** * 资讯页面右侧广告图 * @return */ @RequestMapping(value = "/informationAdvertisimg",method = RequestMethod.POST) public String informationAdvertisimg(int address){ String Json = StringUtil.filterFieldsJson(informationBusiness.findAllImgByadvertImg(address),Picture.class,"id","imgTitle"); return Json; }
最终返回效果:
注意:若返回值出现反斜杠时估计是序列化了两次导致的。