Spring MVC中的模型对象

时间:2019-02-16 12:00:59

标签: java spring-mvc

我们在模型对象内部添加的属性的范围是什么? 例如: Foo foo =新的Foo(); model.addAttribute(“ foo”,foo); 可以将“ foo”用于多个请求吗?

1 个答案:

答案 0 :(得分:0)

据我所知,“模型”是Springs接口,在Controllers中用于将数据返回到视图。 在您的JSP中,您应该能够通过$ {foo}打印Foo对象,因为您已将其添加到models属性。只是针对当前请求。

示例: https://www.javatpoint.com/spring-mvc-model-interface

如果您想要多个请求中的某些内容,则应使用会话对象。 在您的控制器中,您可以使用HttpServletRequest request.getSession().addAttribute(foo); 并按照此处Print session attributes in jsp的说明进行打印。