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

被折叠的 条评论
为什么被折叠?



