前言
在SpringBoot中,是没有配置工程的xml文件,这也是SpringBoot的一大优势所在。
SpringBoot的是推荐使用Thymeleaf模板,这个我就不吐槽了。SpringBoot中的HTML静态资源通常是放在resource下的static文件夹先,放在这个文件夹下的HTML文件,可以直接通过端口号后直接加html名称就可以直接访问。
但是需要我们在输入端口号或者系统名称时就可以访问首页。
解决方法
public class JarvisApplication {
public static void main(String[] args) {
SpringApplication.run(JarvisApplication.class, args);
}
/**
* 设置首页信息
*/
@Configuration
public class IndexController extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("redirect:/index");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
}