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;
    }

 

 

最終返回效果:

 

注意:若返回值出現反斜杠時估計是序列化了兩次導致的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM