SpringBoot靜態(tài)資源路徑配置及主頁顯示
靜態(tài)資源路徑
靜態(tài)資源支持放在以下路徑中,訪問優(yōu)先級從上到下:
classpath:/META-INF/resources/classpath:/resources/classpath:/static/ # 默認路徑classpath:/public/
其中 classpath 為 src/main/resources 目錄。
請求地址為:http://localhost:8080/xx.js
首頁
文件位置:
classpath:/static/favicon.icoclasspath:/templates/index.html
導入 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>
定義請求控制器:
@Controllerpublic class IndexController { @RequestMapping({'/', '/index.html'}) public String index(Model model){ model.addAttribute('msg', 'Hello, Thymeleaf!'); return 'index'; }}
加入模板內容顯示首頁:
<!DOCTYPE html><html lang='en' xmlns:th='http://www.thymeleaf.org'><head> <meta charset='UTF-8'> <title>index page</title></head><body><h1>首頁</h1><div th:text='${msg}'></div></body></html>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. 使用Python webdriver圖書館搶座自動預約的正確方法2. Python3 json模塊之編碼解碼方法講解3. Python 合并拼接字符串的方法4. ASP基礎知識VBScript基本元素講解5. Linux刪除系統(tǒng)自帶版本Python過程詳解6. Android 簡單的實現(xiàn)滑塊拼圖驗證碼功能7. 淺談由position屬性引申的css進階討論8. ASP.NET MVC使用jQuery ui的progressbar實現(xiàn)進度條9. PHP如何開啟Opcache功能提升程序處理效率10. 在線php代碼縮進、代碼美化工具:PHP Formatter

網(wǎng)公網(wǎng)安備