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