Spring boot 默认首页配置
Spring boot没有了web.xml配置文件,那首页该如何设置那?
首页文件需要放到static目录下,具体项目结构如下图所示:
添加配置类,其代码如下:
复制代码
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:/login.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
}
此时通过IP+端口号,就可以访问默认首页了