行业知识
springboot整合vue,将vue项目整合到springboot项目中
2026-11-11 21:16:26
来源:互联网转载
将vue项目打包后,与springboot项目整合。
第一步,使用springboot中的thymeleaf模板引擎
导入依赖
org.springframework.boot spring-boot-starter-thymeleaf
在resources目录下建立static文件夹和templates文件夹
在yml中配置thymeleaf
spring: # 模板引擎 thymeleaf: mode: HTML5 encoding: utf-8 # 禁用缓存 cache: false
在配置中打开访问静态文件的权限
public class ResourceConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); }} 第二步:将vue项目打包后中的静态文件放入static文件夹中,将index.html放入templates文件夹中
第三步:在controller中写路由,让其跳转index.html页面
@Controller@CrossOriginpublic class IndexController { @GetMapping("/") public String index(){ return "index"; }}
上一篇:方舟怎么在本服务器说话?