[url]http://wanghongxu.iteye.com/blog/1345325[/url]
mvc:view-controller可以在不需要Controller处理request的情况,转向到设置的View
或者用xml设置方式
重定向
即如果当前路径是/ 则重定向到/admin/index
访问静态资源文件
mvc:view-controller可以在不需要Controller处理request的情况,转向到设置的View
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("home");
}
} 或者用xml设置方式
<mvc:view-controller path="/" view-name="home"/>重定向
<mvc:view-controller path="/" view-name="redirect:/admin/index"/>即如果当前路径是/ 则重定向到/admin/index
访问静态资源文件
<mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/>
本文介绍如何使用Spring MVC框架配置视图控制器以实现不同类型的页面跳转,包括直接显示视图、重定向以及访问静态资源文件的方法。
2025

被折叠的 条评论
为什么被折叠?



