SpringBoot靜態(tài)資源路徑配置及主頁(yè)顯示
靜態(tài)資源路徑
靜態(tài)資源支持放在以下路徑中,訪問(wèn)優(yōu)先級(jí)從上到下:
classpath:/META-INF/resources/classpath:/resources/classpath:/static/ # 默認(rèn)路徑classpath:/public/
其中 classpath 為 src/main/resources 目錄。
請(qǐng)求地址為:http://localhost:8080/xx.js
首頁(yè)
文件位置:
classpath:/static/favicon.icoclasspath:/templates/index.html
導(dǎo)入 thymeleaf 模板引擎依賴:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring5</artifactId> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-java8time</artifactId> </dependency></dependencies>
定義請(qǐng)求控制器:
@Controllerpublic class IndexController { @RequestMapping({'/', '/index.html'}) public String index(Model model){ model.addAttribute('msg', 'Hello, Thymeleaf!'); return 'index'; }}
加入模板內(nèi)容顯示首頁(yè):
<!DOCTYPE html><html lang='en' xmlns:th='http://www.thymeleaf.org'><head> <meta charset='UTF-8'> <title>index page</title></head><body><h1>首頁(yè)</h1><div th:text='${msg}'></div></body></html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. springcloud alibaba nacos linux配置的詳細(xì)教程2. Vue為什么要謹(jǐn)慎使用$attrs與$listeners3. SpringBoot 使用 @Value 注解讀取配置文件給靜態(tài)變量賦值4. Java 生成帶Logo和文字的二維碼5. SpringBoot整合MybatisPlus的教程詳解6. 解決在Vue中使用axios POST請(qǐng)求變成OPTIONS的問(wèn)題7. Spring Boot2發(fā)布調(diào)用REST服務(wù)實(shí)現(xiàn)方法8. python 實(shí)現(xiàn)圖片修復(fù)(可用于去水印)9. Android自定義控件實(shí)現(xiàn)方向盤(pán)效果10. python中的socket實(shí)現(xiàn)ftp客戶端和服務(wù)器收發(fā)文件及md5加密文件
