我有一个设置一些 flash 属性并调用重定向的 Controller 。我还有一个 before Controller 拦截器,它将拦截重定向的 URL 并强制另一个重定向。此时,我的 Flash 属性被删除,因为 spring 认为重定向目标已实现。
我想维护这些属性,以便我的第二个 Controller 可以在第二次重定向后访问它们。
任何可能的方法来实现这一目标?
请注意,我无法更改最初填充它们的第一个 Controller ,我需要这些属性才能到达第二个重定向 Controller 。
最佳答案
在您的 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);
关于spring - 重定向完成后维护Spring flash属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18338675/