完成重定向后维护Spring flash属性

bah*_*haa 4 spring spring-mvc

我有一个控制器,设置一些Flash属性并调用重定向.我还有一个前控制器拦截器,它将拦截重定向的URL并强制另一个重定向.此时,我的Flash属性被删除,因为Spring认为重定向目标已经完成.

我想保留这些属性,以便我的第二个控制器可以在第二次重定向后访问它们.

任何可能的实现方式?

请注意,我无法更改最初填充它们的第一个控制器,我需要这些属性才能到达第二个重定向控制器.

Sot*_*lis 5

在你的内部HandlerInterceptor,你应该做以下事情

FlashMap lastAttributes = RequestContextUtils.getInputFlashMap(request); // should hold the attributes from your last request       
FlashMap forNextRequest = RequestContextUtils.getOutputFlashMap(request); // will hold the attributes for your next request
forNextRequest.putAll(lastAttributes);
Run Code Online (Sandbox Code Playgroud)