SpringBoot整合模板引擎過程代碼實(shí)例
一、SpringBoot整合freemarker:
1.引入freemarker模板依賴:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> <version>1.5.9.RELEASE</version> </dependency>
2.配置application.properties:
#freemarker 靜態(tài)資源配置 #設(shè)定ftl文件路徑 spring.freemarker.template-loader-path=classpath:/templates #關(guān)閉緩存,還是刷新,上線生產(chǎn)環(huán)境需要改為true spring.freemarker.cache=false spring.freemarker.charset=utf-8 spring.freemarker.check-template-location=true spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose-session-attributes=true spring.freemarker.request-context-attribute=request spring.freemarker.suffix=.ftl
3.在resources目錄下建個目錄叫templates,在這個目錄下新建一個以.ftl結(jié)尾的文件,并且將html代碼復(fù)制進(jìn)去,在controller層返回這個視圖
二、SpringBoot整合thymeleaf
1.引入thymeleaf模板依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>1.5.9.RELEASE</version> </dependency>
2.配置application.properties:
#thymeleaf靜態(tài)資源配置 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html #關(guān)閉緩存,即時刷新,上線生產(chǎn)環(huán)境需要改為true spring.thymeleaf.cache=true
3.在resoureces下新建個目錄templates在里面編寫html文件,具體的thymeleaf標(biāo)簽語法這里就不做介紹了。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- SpringBoot項目中的視圖解析器問題(兩種)
- Springboot視圖解析器ViewResolver使用實(shí)例
- SpringBoot超詳細(xì)講解Thymeleaf模板引擎
- springboot學(xué)習(xí)之Thymeleaf模板引擎及原理介紹
- Java SpringBoot模板引擎之 Thymeleaf入門詳解
- SpringBoot使用Thymeleaf模板引擎訪問靜態(tài)html的過程
- Springboot整合thymleaf模板引擎過程解析
- 詳解SpringBoot+Thymeleaf 基于HTML5的現(xiàn)代模板引擎
- SpringBoot引入模板引擎實(shí)現(xiàn)視圖解析
相關(guān)文章
使用Java模擬鼠標(biāo)和鍵盤的詳細(xì)操作步驟
這篇文章主要介紹了使用Java模擬鼠標(biāo)和鍵盤的詳細(xì)操作步驟,要運(yùn)行上面提供的Java程序,您需要遵循幾個步驟來設(shè)置Java環(huán)境、編寫程序代碼,并執(zhí)行該程序,文中有相關(guān)的代碼示例,需要的朋友可以參考下2024-05-05
Spring框架應(yīng)用的權(quán)限控制系統(tǒng)詳解
在本篇文章里小編給大家整理的是關(guān)于基于Spring框架應(yīng)用的權(quán)限控制系統(tǒng)的研究和實(shí)現(xiàn),需要的朋友們可以學(xué)習(xí)下。2019-08-08
java基礎(chǔ)理論Stream的Filter與謂詞邏輯
這篇文章主要為大家介紹了java基礎(chǔ)理論Stream的Filter與謂詞邏輯,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03
servlet之ServletContext簡介_動力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了servlet之ServletContext簡介,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07
Springmvc 4.x利用@ResponseBody返回Json數(shù)據(jù)的方法
這篇文章主要介紹了Springmvc 4.x利用@ResponseBody返回Json數(shù)據(jù)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04

