控制器传递到另一个控制器

控制器传递到另一个控制器

本文介绍了如何将模型属性从一个 Spring MVC 控制器传递到另一个控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一个控制器重定向到另一个控制器.但我还需要将模型属性传递给第二个控制器.

I am redirecting from a controller to another controller. But I also need to pass model attributes to the second controller.

我不想将模型放入会话中.

I don't want to put the model in session.

请帮忙.

推荐答案

我认为最优雅的方式是在 Spring MVC 中实现自定义 Flash Scope.

I think that the most elegant way to do it is to implement custom Flash Scope in Spring MVC.

Flash Scope 的主要思想是将数据从一个控制器存储到第二个控制器中的下一次重定向

the main idea for the flash scope is to store data from one controller till next redirect in second controller

请参考我对自定义范围问题的回答:

Please refer to my answer on the custom scope question:

Spring MVC 自定义作用域 bean

此代码中唯一缺少的是以下 xml 配置:

The only thing that is missing in this code is the following xml configuration:

<bean id="flashScopeInterceptor" class="com.vanilla.springMVC.scope.FlashScopeInterceptor" />
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
  <property name="interceptors">
    <list><ref bean="flashScopeInterceptor"/></list>
  </property>
</bean>

这篇关于如何将模型属性从一个 Spring MVC 控制器传递到另一个控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:35