将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: HTML5
    encoding: utf-8
    # 禁用缓存
    cache: false

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

public class ResourceConfig implements WebMvcConfigurer {
    @Override
    public 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";
    }
}

运行项目

输入端口并进行访问!

相关推荐

  1. 服务器部署Springboot项目

    2024-07-17 21:12:03       68 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 21:12:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 21:12:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 21:12:03       58 阅读
  4. Python语言-面向对象

    2024-07-17 21:12:03       69 阅读

热门阅读

  1. 构建新纪元:Gradle中Kotlin插件的配置全指南

    2024-07-17 21:12:03       22 阅读
  2. 软设之命令模式

    2024-07-17 21:12:03       21 阅读
  3. Linux系统中调试蓝牙的常用命令

    2024-07-17 21:12:03       19 阅读
  4. C++中调用Pytorch模型

    2024-07-17 21:12:03       18 阅读
  5. 若依自定义文件上传下载

    2024-07-17 21:12:03       17 阅读
  6. 蓝牙芯片智能秤解决方案

    2024-07-17 21:12:03       19 阅读
  7. 深度解析:《聚类算法研究》综述论文精粹

    2024-07-17 21:12:03       20 阅读
  8. 全网 最强 最全 Linux 命令总结

    2024-07-17 21:12:03       16 阅读