我将实现一个 Spring MVC 控制器,它使用作为参数传递的动态视图来查看:
@Controller
@RequestMapping("/page")
public class PageController {
@RequestMapping(value = "/{page}", method = {RequestMethod.GET})
public ModelAndView page(@PathVariable("page")String page) {
System.out.println("page = " + page);
return new ModelAndView(page);
}
}
视图由 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"/>
<property name="cache" value="false"/>
</bean>
当请求不存在的视图时,有什么方法可以返回默认视图?也许要检查是否存在视图,然后返回new ModelAndView('requested_page_not_found')
?