如何将模型属性从一个Spring MVC控制器传递到另一个控制器? [英] How to pass model attributes from one Spring MVC controller to another controller?

查看:174
本文介绍了如何将模型属性从一个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作用域的主要思想是将数据从一个控制器存储到第二个控制器中的下一个重定向

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控制器传递到另一个控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆