1). 打包Vue項(xiàng)目
- 修改配置
將/config/
目錄下的index.js打開修改李皇,將build中assetsPublicPath屬性修改為'./'
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
}
- 打包
在項(xiàng)目的根目錄下執(zhí)行npm run build
,執(zhí)行成功后采转,在dist文件夾生成static文件夾和index.html文件
2). 創(chuàng)建文件夾
在SpringBoot項(xiàng)目中跨扮,并將第1步中dist文件夾中的內(nèi)容全部拷貝到/src/main/resources/static/
文件夾下
3). 配置application.yml
配置prefix,suffix和static-locations
# spring 配置
spring:
mvc:
view:
# 如果配置了spring-resources,則必須包含classpath:/static/
# 訪問靜態(tài)頁面 /pages/指定路徑為 /static/pages/
prefix: /
# 靜態(tài)頁面后綴
suffix: .html
resources:
# 靜態(tài)文件路徑, 資源路徑,博客路徑
static-locations: classpath:/static/, classpath:/blog/
4). Controller配置
@Controller
class HomeController {
/**
* 訪問首頁方式
* 切記不能配置index.html
*/
@GetMapping("/", "/index")
fun index() : String{
return "index"
}
}