首页 > Web开发 > 详细

HTTP response 添加body

时间:2018-05-18 10:29:58      阅读:1578      评论:0      收藏:0      [点我收藏+]

在拦截器中进行拦截操作时,想要给response添加body,如何操作?

    /**
     * 返回JSON数据
     * @param response
     * @param obj
     * @throws Exception
     */
    public static void responseJson(HttpServletResponse response, Object obj) throws Exception {
        response.setContentType("application/json; charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.print(JSONObject.toJSONString(obj, SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteDateUseDateFormat));
        writer.close();
        response.flushBuffer();
    }

调用

responseJson(response, new APIRespJson(resultCode));

 

HTTP response 添加body

原文:https://www.cnblogs.com/thiaoqueen/p/9054759.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!