spring boot 配置默认首页
原创 loonbs 发表于:2021-11-18 19:39:48
  阅读 :89   收藏   编辑

添加配置类,其代码如下

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 WebMvcConf implements WebMvcConfigurer {

  /**
   * 配置首页访问地址 WEB-INF下的index.jsp
   * @param registry
   */
  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("forward:/index");
    registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
  }
}