Spring boot没有了web.xml配置文件,那首页该如何设置那?

首页文件需要放到static目录下,具体项目结构如下图所示:

Spring boot 默认首页配置

添加配置类,其代码如下:

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.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}

此时通过IP+端口号,就可以访问默认首页了。

相关文章:

  • 2021-05-26
  • 2021-11-20
  • 2021-11-20
  • 2021-11-22
  • 2022-01-07
  • 2021-05-04
  • 2021-09-24
  • 2021-11-19
猜你喜欢
  • 2021-09-23
  • 2021-11-22
  • 2021-05-19
  • 2021-12-02
  • 2021-11-22
  • 2021-10-06
  • 2022-01-07
  • 2021-12-30
相关资源
相似解决方案