最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring boot 配置freemarker及如何使用freemarker渲染頁面

 更新時間:2023年10月30日 15:04:16   作者:寂夜了無痕  
springboot中自帶的頁面渲染工具為thymeleaf 還有freemarker這兩種模板引擎,本文重點給大家介紹spring boot 配置freemarker及如何使用freemarker渲染頁面,感興趣的朋友一起看看吧

1.springboot 中自帶的頁面渲染工具為thymeleaf 還有freemarker 這兩種模板引擎 簡單比較下兩者不同

1.1freemaker 優(yōu)點

freemarker 不足:thymeleaf由于使用了標(biāo)簽屬性做為語法,模版頁面直接用瀏覽器渲染,使得前端和后端可以并行開發(fā)。freemarket使用</>這樣的語法,就無法直接使瀏覽器渲染出原本頁面的樣子。

thymeleaf優(yōu)點:

靜態(tài)html嵌入標(biāo)簽屬性,瀏覽器可以直接打開模板文件,便于前后端聯(lián)調(diào)。 springboot官方推薦方案。

thymeleaf缺點:

模板必須符合xml規(guī)范 比較下兩者

1.從寫code的習(xí)慣角度可能freemarker更習(xí)慣于我們的思維。
2.不過從前后分離開發(fā)的角度看thymeleaf更合適,值的綁定都是基于html的dom元素屬性的,適合前后聯(lián)調(diào)。

還是回歸下主題

開始編碼:

1.引入pom依賴

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

2.向yml格式配置文件添加內(nèi)容

spring:
  freemarker:
    request-context-attribute: req  #req訪問request
    suffix: .html  #后綴名
    content-type: text/html
    enabled: true
    cache: false #緩存配置
    template-loader-path: classpath:/templates/ #模板加載路徑 按需配置
    charset: UTF-8 #編碼格式
    settings:
      number_format: '0.##'   #數(shù)字格式化,無小數(shù)點

3.測試接口如圖

4.index文件位置如圖

index 內(nèi)容

5.啟動項目如圖

index頁面渲染成功

網(wǎng)上收集 propertity的freemarker 配置 (propertity格式配置文件)

 # FREEMARKER (FreeMarkerAutoConfiguration)
spring.freemarker.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.allow-session-override=false # Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.cache=false # Enable template caching.
spring.freemarker.charset=UTF-8 # Template encoding.
spring.freemarker.check-template-location=true # Check that the templates location exists.
spring.freemarker.content-type=text/html # Content-Type value.
spring.freemarker.enabled=true # Enable MVC view resolution for this technology.
spring.freemarker.expose-request-attributes=false # Set whether all request attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-session-attributes=false # Set whether all HttpSession attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-spring-macro-helpers=true # Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".
spring.freemarker.prefer-file-system-access=true # Prefer file system access for template loading. File system access enables hot detection of template changes.
spring.freemarker.prefix= # Prefix that gets prepended to view names when building a URL.
spring.freemarker.request-context-attribute= # Name of the RequestContext attribute for all views.
spring.freemarker.settings.*= # Well-known FreeMarker keys which will be passed to FreeMarker's Configuration.
spring.freemarker.suffix= # Suffix that gets appended to view names when building a URL.
spring.freemarker.template-loader-path=classpath:/templates/ # Comma-separated list of template paths.
spring.freemarker.view-names= # White list of view names that can be resolved.

另外需要使用thymeleaf 可以使用如下配置(yml 格式配置文件方式)

##視圖模型
spring:
  thymeleaf:
    prefix: classpath:/templates/
    suffix: .html
    cache: false
    encoding: utf-8
    content-type: text/html
    check-template-location: true

到此這篇關(guān)于spring boot 配置freemarker及使用freemarker渲染頁面的文章就介紹到這了,更多相關(guān)spring boot 配置freemarker內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java結(jié)構(gòu)型設(shè)計模式之組合模式Composite Pattern詳解

    Java結(jié)構(gòu)型設(shè)計模式之組合模式Composite Pattern詳解

    組合模式,又叫部分整體模式,它創(chuàng)建了對象組的數(shù)據(jù)結(jié)構(gòu)組合模式使得用戶對單個對象和組合對象的訪問具有一致性。本文將通過示例為大家詳細(xì)介紹一下組合模式,需要的可以參考一下
    2022-11-11
  • 一篇文章帶你了解Java基礎(chǔ)-多態(tài)

    一篇文章帶你了解Java基礎(chǔ)-多態(tài)

    這篇文章主要介紹了Java 多態(tài)的深入理解的相關(guān)資料,子類繼承父類的特征和行為,使得子類具有父類的各種屬性和方法。或子類從父類繼承方法,使得子類具有父類相同的行為,需要的朋友可以參考下
    2021-08-08
  • SpringBoot MongoDB 索引沖突分析及解決方法

    SpringBoot MongoDB 索引沖突分析及解決方法

    這篇文章主要介紹了SpringBoot MongoDB 索引沖突分析及解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • Spring Cloud中使用Eureka的詳細(xì)過程

    Spring Cloud中使用Eureka的詳細(xì)過程

    Eureka 是 Netflix 開源的一個服務(wù)發(fā)現(xiàn)組件,它在微服務(wù)架構(gòu)中扮演著重要的角色,這篇文章主要介紹了Spring Cloud中如何使用Eureka,需要的朋友可以參考下
    2024-07-07
  • Spring Boot和Docker實現(xiàn)微服務(wù)部署的方法

    Spring Boot和Docker實現(xiàn)微服務(wù)部署的方法

    這篇文章主要介紹了Spring Boot和Docker實現(xiàn)微服務(wù)部署的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • 詳解關(guān)于mybatis-plus中Service和Mapper的分析

    詳解關(guān)于mybatis-plus中Service和Mapper的分析

    這篇文章主要介紹了詳解關(guān)于mybatis-plus中Service和Mapper的分析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • Java實現(xiàn)角色扮演游戲的示例代碼

    Java實現(xiàn)角色扮演游戲的示例代碼

    這篇文章主要介紹了通過Java語言實現(xiàn)的自制的角色扮演游戲,選擇兩個角色,然后進(jìn)行PK,可用來學(xué)習(xí)JAVA的接口,繼承和多態(tài)。需要的可以參考一下
    2022-02-02
  • springboot 3.x 整合 RocketMQ 5.x的詳細(xì)過程

    springboot 3.x 整合 RocketMQ 5.x的詳細(xì)過程

    本文介紹了如何在SpringBoot中使用RocketMQ 5.x客戶端,包括依賴配置、參數(shù)設(shè)置、生產(chǎn)者和消費者的消息發(fā)送與接收示例以及服務(wù)端環(huán)境搭建,感興趣的朋友跟隨小編一起看看吧
    2025-12-12
  • 【面試】Spring事務(wù)面試考點吐血整理(建議珍藏)

    【面試】Spring事務(wù)面試考點吐血整理(建議珍藏)

    本文是小編給大家收藏整理的Spring事務(wù)面試考點,非常不錯,值得收藏,感興趣的朋友參考下吧
    2019-04-04
  • JAVA 十六進(jìn)制與字符串的轉(zhuǎn)換

    JAVA 十六進(jìn)制與字符串的轉(zhuǎn)換

    筆者前幾日在開服過程中需要將字符串轉(zhuǎn)化成為16進(jìn)制的字符串,在網(wǎng)上找到了一些方法嘗試之后,均發(fā)現(xiàn)存在一個問題-->字符串轉(zhuǎn)為16進(jìn)制后再轉(zhuǎn)回來,英文正常,中文出現(xiàn)亂碼
    2009-05-05

最新評論

金溪县| 红桥区| 合水县| 永顺县| 岢岚县| 西丰县| 闸北区| 云梦县| 阜新| 通道| 皋兰县| 正定县| 淳化县| 荔波县| 蒙阴县| 广州市| 犍为县| 忻城县| 贵阳市| 莱州市| 北票市| 汶川县| 马鞍山市| 饶河县| 古浪县| 油尖旺区| 正蓝旗| 西林县| 苍南县| 福泉市| 东宁县| 夏津县| 雅安市| 额敏县| 枞阳县| 永州市| 剑阁县| 定州市| 西丰县| 建阳市| 乐至县|