/**
 * @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 即可!

完成!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注