zoukankan      html  css  js  c++  java
  • FastJson过滤掉不需要的返回字段

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

    最终返回效果:

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

  • 相关阅读:
    CodeForces
    Codeforces 1523D Love-Hate(随机化算法,sos dp)
    CodeForces
    讲题泛做
    CF vp 新题乱做
    10.11 牛客
    10.6 牛客
    10.4 牛客
    10.9 模拟考试 题解报告
    9.18 校内模拟赛 题解报告
  • 原文地址:https://www.cnblogs.com/tongxuping/p/7643985.html
Copyright © 2011-2022 走看看