在springboot中一般配合thymeleaf模板使用,
localhost:8080/ ,默认的访问路径是index.html 或者/
如果你需要访问设置默认页面为其他页面,只需要新建一个MyWebConfig
让它实现 WebMvcConfigurer
具体代码如下:
/** * 拦截某个请求跳转固定位置 * * @param registry */ @Override public void addViewControllers(ViewControllerRegistry registry) { //super.addViewControllers(registry); registry.addViewController("/").setViewName("welcome"); // // registry.addViewController("/").setViewName("index"); // registry.addViewController("/index.html").setViewName("index"); }