/**
 * @Author: 臧立昆
 * @Email: 740969606@qq.com
 * @Date: 2020/8/1
 * @Time: 16:28
 */
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class IndexViewConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //设置访问路径为 “/” 跳转到指定页面
        registry.addViewController("/").setViewName("forward:/index.html");
        registry.addViewController("/hello").setViewName("forward:/doc.html");
        //设置为最高优先级
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}

然后 在resources文件夹下面创建一个static的文件夹 里面放一个叫 index.html 即可, 访问项目路径,就跳到首页了。

doc.html是一个knife4j的文档地址,访问项目路径后加一个/hello,就可以实现 跳转到knife4j文档地址!

启动出现:WelcomePageHandlerMapping 即可!

完成!

特殊说明:
上述文章均是作者实际操作后产出。烦请各位,请勿直接盗用!转载记得标注原文链接:www.zanglikun.com
第三方平台不会及时更新本文最新内容。如果发现本文资料不全,可访问本人的Java博客搜索:标题关键字。以获取全部资料 ❤