//package com.ssm.filter;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.ServletOutputStream;
//import javax.servlet.WriteListener;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpServletResponseWrapper;
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.OutputStreamWriter;
//import java.io.PrintWriter;
//import java.math.BigDecimal;
//import java.nio.charset.StandardCharsets;
//
//@Slf4j
//public class ResponseInterceptor implements HandlerInterceptor {
//    private static ThreadLocal<ByteArrayOutputStream> bufferThreadLocal = new ThreadLocal<>();
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
//                           ModelAndView modelAndView) throws Exception {
//        ByteArrayOutputStream buffer = bufferThreadLocal.get();
//        String responseBody = null;
//        if (buffer != null) {
//            responseBody = buffer.toString(response.getCharacterEncoding()).trim();
//        }
//
//        // 在这里对响应数据进行处理
//
//        // 输出响应数据（可选）
//        if (responseBody != null && !responseBody.isEmpty()) {
//            response.getWriter().write(responseBody);
//        }
//      log.error("拦截器生效了");
//        // 获取响应的输出流
//    }
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        // 创建缓冲区
//        bufferThreadLocal.set(new ByteArrayOutputStream());
//        return true;
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        // 移除缓冲区
//        bufferThreadLocal.remove();
//    }
//
//}
