改过默认视图的不适用于此方法,要先把视图改回默认
找到vue的dist目录
index.html拷贝到templates目录
其他文件拷贝到static目录
yml文件配置
spring:
thymeleaf:
option: classpath:/templates/
suffix: .html
mode: HTML
encoding: UTF-8
cache: false
servlet:
content-type: text/html
新建config文件 映射静态html文件
@Configuration
public class WebMvcConfigure implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry){
registry.addViewController("/index.html").setViewName("index");
}
}
config的另一种写法,使用Controller
@Controller
public class IndexController {
@RequestMapping("/")
public String index(){
return "index";
}
@RequestMapping("/index.html")
public String indexHtml(){
return "index";
}
}
其他可能需要的静态配置
@Configuration
public class WebMvcConfigure implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
}
maven配置引入
dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
之后可以访问 http://localhost:8080/index.html 了