SpringBoot整合模板引擎過(guò)程代碼實(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)境需要改為truespring.freemarker.cache=falsespring.freemarker.charset=utf-8spring.freemarker.check-template-location=truespring.freemarker.content-type=text/htmlspring.freemarker.expose-request-attributes=truespring.freemarker.expose-session-attributes=truespring.freemarker.request-context-attribute=requestspring.freemarker.suffix=.ftl
3.在resources目錄下建個(gè)目錄叫templates,在這個(gè)目錄下新建一個(gè)以.ftl結(jié)尾的文件,并且將html代碼復(fù)制進(jìn)去,在controller層返回這個(gè)視圖
二、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=.htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/html#關(guān)閉緩存,即時(shí)刷新,上線生產(chǎn)環(huán)境需要改為truespring.thymeleaf.cache=true
3.在resoureces下新建個(gè)目錄templates在里面編寫(xiě)html文件,具體的thymeleaf標(biāo)簽語(yǔ)法這里就不做介紹了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python如何批量生成和調(diào)用變量2. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無(wú)效問(wèn)題3. Python基于requests實(shí)現(xiàn)模擬上傳文件4. python利用opencv實(shí)現(xiàn)顏色檢測(cè)5. Python sorted排序方法如何實(shí)現(xiàn)6. Python 中如何使用 virtualenv 管理虛擬環(huán)境7. 通過(guò)CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫(huà)特效8. ASP.NET MVC實(shí)現(xiàn)橫向展示購(gòu)物車(chē)9. ASP.Net Core(C#)創(chuàng)建Web站點(diǎn)的實(shí)現(xiàn)10. Python獲取B站粉絲數(shù)的示例代碼
