在拦截器中进行拦截操作时,想要给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