美文网首页
SpringBoot设置默认首页

SpringBoot设置默认首页

作者: _灯火阑珊处 | 来源:发表于2018-09-29 15:11 被阅读0次

    新建一个类继承WebMvcConfigurerAdapter
    重写addViewControllers方法即可

    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.WebMvcConfigurerAdapter;
    
    @Configuration
    public class DefaultPageConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("index");
            registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
            super.addViewControllers(registry);
        }
    }
    
    

    registry.addViewController("/").setViewName("index");
    "index" 为要设置成首页页面的文件名称

    相关文章

      网友评论

          本文标题:SpringBoot设置默认首页

          本文链接:https://www.haomeiwen.com/subject/kkxboftx.html