SpringBoot整合模板引擎過程代碼實例
一、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)資源配置#設定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目錄下建個目錄叫templates,在這個目錄下新建一個以.ftl結(jié)尾的文件,并且將html代碼復制進去,在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=.htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/html#關(guān)閉緩存,即時刷新,上線生產(chǎn)環(huán)境需要改為truespring.thymeleaf.cache=true
3.在resoureces下新建個目錄templates在里面編寫html文件,具體的thymeleaf標簽語法這里就不做介紹了。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python GUI庫圖形界面開發(fā)之PyQt5動態(tài)(可拖動控件大小)布局控件QSplitter詳細使用方法與實例2. CSS3實例分享之多重背景的實現(xiàn)(Multiple backgrounds)3. js開發(fā)中的頁面、屏幕、瀏覽器的位置原理(高度寬度)說明講解(附圖)4. CSS清除浮動方法匯總5. 不要在HTML中濫用div6. XML入門的常見問題(三)7. Python數(shù)據(jù)分析JupyterNotebook3魔法命令詳解及示例8. ASP動態(tài)include文件9. ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫金額)的函數(shù)10. vue跳轉(zhuǎn)頁面常用的幾種方法匯總
