/**
     * @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;
    }

 

 

最终返回效果:

FastJson过滤掉不需要的返回字段

 

注意:若返回值出现反斜杠时估计是序列化了两次导致的。

相关文章:

  • 2022-12-23
  • 2019-09-03
  • 2021-10-14
  • 2022-02-05
  • 2021-04-06
  • 2022-12-23
  • 2021-12-02
  • 2021-07-11
猜你喜欢
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案