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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-11
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2023-03-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案