1

在 Spring 将输出内容刷新到页面之前,有没有正确的方法可以修改输出内容?内容准备好后,我需要运行正则表达式来修复所有链接。

假设我使用拦截器,我如何获取渲染的内容,修改它并将其设置回来?

public class SpringControllerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle");

    }
}
4

2 回答 2

1

您可以添加一个Filter层来处理您的响应,您可以抓取整个响应正文并处理您想要的链接

于 2012-12-17T22:05:06.623 回答
0

Spring MVC Interceptor would be the one of the way of doing this. Override postHandle method to update the http response object.

void postHandle(HttpServletRequest request,
                HttpServletResponse response,
                Object handler,
                ModelAndView modelAndView)
                throws Exception

Intercept the execution of a handler. Called after HandlerAdapter actually invoked the handler, but before the DispatcherServlet renders the view.

Read more:

  1. Spring MVC Interceptor example
  2. Spring Interceptor Documentation
于 2012-12-17T22:21:20.430 回答