1 Star 0 Fork 29

柚子 / notebook

forked from JustryDeng / notebook 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
[04]spring-mvc配置访问根路径时重定向至指定路径.md 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
邓沙利文 提交于 2022-08-03 17:43 . 优化author

spring-mvc配置访问根路径时重定向至指定路径

配置

低版本继承org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter,高版本实现org.springframework.web.servlet.config.annotation.WebMvcConfigurer

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * (non-javadoc)
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2022/6/24 15:28
 */
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {
    
    /**
     * 将请求"/"重定向至 指定路径
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 示例1
        // registry.addViewController("/").setViewName("redirect:/user/list");
        // 示例2
        registry.addViewController("/").setViewName("redirect:/index.html");
    }
}
1
https://gitee.com/WY784755850/notebook.git
git@gitee.com:WY784755850/notebook.git
WY784755850
notebook
notebook
master

搜索帮助