SpringBoot整合模板引擎過(guò)程代碼實(shí)例
一、SpringBoot整合freemarker:
1.引入freemarker模板依賴(lài):
<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)閉緩存,還是刷新,上線(xià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目錄下建個(gè)目錄叫templates,在這個(gè)目錄下新建一個(gè)以.ftl結(jié)尾的文件,并且將html代碼復(fù)制進(jìn)去,在controller層返回這個(gè)視圖
二、SpringBoot整合thymeleaf
1.引入thymeleaf模板依賴(lài)
<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)閉緩存,即時(shí)刷新,上線(xiàn)生產(chǎn)環(huán)境需要改為true spring.thymeleaf.cache=true
3.在resoureces下新建個(gè)目錄templates在里面編寫(xiě)html文件,具體的thymeleaf標(biāo)簽語(yǔ)法這里就不做介紹了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- SpringBoot項(xiàng)目中的視圖解析器問(wèn)題(兩種)
- Springboot視圖解析器ViewResolver使用實(shí)例
- SpringBoot超詳細(xì)講解Thymeleaf模板引擎
- springboot學(xué)習(xí)之Thymeleaf模板引擎及原理介紹
- Java SpringBoot模板引擎之 Thymeleaf入門(mén)詳解
- SpringBoot使用Thymeleaf模板引擎訪(fǎng)問(wèn)靜態(tài)html的過(guò)程
- Springboot整合thymleaf模板引擎過(guò)程解析
- 詳解SpringBoot+Thymeleaf 基于HTML5的現(xiàn)代模板引擎
- SpringBoot引入模板引擎實(shí)現(xiàn)視圖解析
相關(guān)文章
java?LockSupport實(shí)現(xiàn)原理示例解析
這篇文章主要為大家介紹了java?LockSupport實(shí)現(xiàn)原理示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01JavaWeb項(xiàng)目中dll文件動(dòng)態(tài)加載方法解析(詳細(xì)步驟)
這篇文章主要介紹了JavaWeb項(xiàng)目中dll文件動(dòng)態(tài)加載方法,步驟詳細(xì),在這里分享給大家,需要的朋友可以了解下。2017-09-09Spring配置shiro時(shí)自定義Realm中屬性無(wú)法使用注解注入的解決辦法
今天小編就為大家分享一篇關(guān)于Spring配置shiro時(shí)自定義Realm中屬性無(wú)法使用注解注入的解決辦法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03springboot yml中profiles的巧妙用法(小白必看多環(huán)境配置)
這篇文章主要介紹了springboot yml中profiles的巧妙用法,非常適合多環(huán)境配置場(chǎng)景,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04詳解Java Project項(xiàng)目打包成jar,并生成exe文件
本篇文章主要介紹了Java Project項(xiàng)目打包成jar,并生成exe文件,非常具有實(shí)用價(jià)值,有興趣的可以了解一下。2017-01-01