SpringBoot靜態(tài)資源路徑配置及主頁顯示
靜態(tài)資源路徑
靜態(tài)資源支持放在以下路徑中,訪問優(yōu)先級從上到下:
classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/ # 默認(rèn)路徑
classpath:/public/
其中 classpath 為 src/main/resources 目錄。
請求地址為:http://localhost:8080/xx.js
首頁
文件位置:
classpath:/static/favicon.ico
classpath:/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>
定義請求控制器:
@Controller public class IndexController { @RequestMapping({"/", "/index.html"}) public String index(Model model){ model.addAttribute("msg", "Hello, Thymeleaf!"); return "index"; } }
加入模板內(nèi)容顯示首頁:
<!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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用Jenkins Pipeline自動化構(gòu)建發(fā)布Java項目的方法
這篇文章主要介紹了使用Jenkins Pipeline自動化構(gòu)建發(fā)布Java項目的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04spring data jpa @Query注解中delete語句報錯的解決
這篇文章主要介紹了spring data jpa @Query注解中delete語句報錯的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12redis 使用lettuce 啟動內(nèi)存泄漏錯誤的解決方案
這篇文章主要介紹了redis 使用lettuce 啟動內(nèi)存泄漏錯誤的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04