Spring MVC 3.0 InternalResourceViewResolver自定义视图文件

时间:2010-02-21 12:36:41

标签: java-ee spring-mvc

我有一个视图解析器:

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

一种方法:

@RequestMapping("/hello_world.html")
public ModelAndView index() {
    ModelAndView mav = new ModelAndView("test");
    return mav;
}

我想渲染/WEB-INF/jsp/test.jsp,但它总是尝试渲染/WEB-INF/jsp/hello_world.jsp

如何在index()中定义custon视图页面?

谢谢

2 个答案:

答案 0 :(得分:1)

导入org.springframework.web.servlet.ModelAndView而不是org.springframework.web.portlet.ModelAndView! ; ^)

答案 1 :(得分:0)

@RequestMapping("/hello_world.html")
public ModelAndView index() {
    ModelAndView mav = new ModelAndView("/test");
    return mav;
}

而不是“测试”,请执行“/ test”