3. springboot中集成部署vue3
·
1. vue3构建
构建命令 npm run build, 构建的结果在disc目录:

2. springboot集成
2.1 拷贝vue3构建结果到springboot resources/static目录

2.2 springboot pom依赖
添加thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.3 application.yml新增thymeleaf配置
server:
port: 8081
spring:
# 打成jar包必须添加如下配置才能找到页面
thymeleaf:
mode: HTML
cache: false
prefix: classpath:/static
2.4 新增后台页面controller
package com.spring.test.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 页面跳转控制器
*/
@Controller
public class PageController {
//后台页面
@RequestMapping("/{backPage}")
public String backPage(@PathVariable String backPage) {
return "/" + backPage;
}
}
2.5 运行springboot并访问后台页面
访问后台页面: http://localhost:8081/index

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)