简体   繁体   English

Spring MVC 3中ModelAndView类的功能

[英]Functioning of ModelAndView class in spring mvc 3

This may sound really stupid but I am unable to understand the flow of Spring MVC in my project. 这听起来确实很愚蠢,但是我无法理解项目中Spring MVC的流程。

When I write the below mentioned code, what happens? 当我编写下面提到的代码时,会发生什么?

ModelAndView mav = new ModelAndView("paging");

I have a paging.jsp in my project but what happens, how does it flow? 我的项目中有paging.jsp ,但是会发生什么,它如何运行?

When you write in your method 当您编写方法时

    ModelAndView mav = new ModelAndView("paging");
    ...
    return mav;

you tell Spring that you return model and view with the name paging . 您告诉Spring您返回模型并使用分页名称进行查看。 In configuration you need to tell Spring how to resolve this name. 在配置中,您需要告诉Spring如何解析该名称。 In your case you could use UrlBasedViewResolver : 在您的情况下,您可以使用UrlBasedViewResolver

<bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

For more information check Spring reference : Resolving Views 有关更多信息,请参见 Spring 参考解析视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM