當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
springboot 设置ico_Spring Boot--Thymeleaf模板引擎/静态页面
生活随笔
收集整理的這篇文章主要介紹了
springboot 设置ico_Spring Boot--Thymeleaf模板引擎/静态页面
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
點關注,不迷路;持續更新Java相關技術及資訊!!!
1.Spring Boot對靜態資源的映射規則
- 如果靜態資源文件夾下有 index.html的話,直接訪問localhost:8080的話,index就是歡迎頁
使用自己的圖標:
在靜態資源文件夾放一個 favicon.ico 的圖標,springboot底層會自動調用這個為我們的圖標
我找了個小叮當的圖標
效果:
自定義靜態資源文件夾
在你的 yml/properties下添加:
spring.resources.static-locations=classpath:/hello/,classpath:/carson/定義之后,原來默認的就不可以使用了
2. 引入 Thymeleaf
SpringBoot推薦使用thymeleaf,因為語法簡單,功能強大, 不推薦使用jsp,默認也不支持jsp
org.springframework.boot spring-boot-starter-thymeleaf新版本的Spring Boot會自動設置好版本,如果你是1.x的Spring Boot,可能要自己更改版本了
3. Thymeleaf 使用&語法
源碼:
@ConfigurationProperties( prefix = "spring.thymeleaf")public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING; public static final String DEFAULT_PREFIX = "classpath:/templates/"; public static final String DEFAULT_SUFFIX = ".html"; private boolean checkTemplate = true; private boolean checkTemplateLocation = true; // 下面是前后綴,也就是說只要放在 prefix 目錄下,就可以被渲染了 private String prefix = "classpath:/templates/"; private String suffix = ".html";這是 nice 標簽
使用:
1.html頁面 導入 thymeleaf 的名稱空間
2.使用thymeleaf語法
- controller:
總結
以上是生活随笔為你收集整理的springboot 设置ico_Spring Boot--Thymeleaf模板引擎/静态页面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql储存过程把集合并_MySQL
- 下一篇: python字典进行大写转化_Pytho