您的位置:首页 > 新闻 > 资讯 > 将vue项目整合到springboot项目中并在阿里云上运行

将vue项目整合到springboot项目中并在阿里云上运行

2025/2/24 13:08:28 来源:https://blog.csdn.net/A18937260063/article/details/140365554  浏览:    关键词:将vue项目整合到springboot项目中并在阿里云上运行

第一步,使用springboot中的thymeleaf模板引擎

导入依赖

        <!-- thymeleaf 模板 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>

在resources目录下建立static文件夹和templates文件夹

在yml中配置thymeleaf

spring:# 模板引擎thymeleaf:mode: HTML5encoding: utf-8# 禁用缓存cache: false

在配置中打开访问静态文件的权限

public class ResourceConfig implements WebMvcConfigurer {@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");}
}

将vue项目打包

npm run build

打包后中的静态文件放入static文件夹中,将index.html放入templates文件夹中

在controller中写路由

让其跳转index.html页面

@Controller
@CrossOrigin
public class IndexController {@GetMapping("/")public String index(){return "index";}
}

运行项目

输入端口并进行访问!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com