日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

Thymeleaf 3 – Thymeleaf 3和Spring MVC快速入门

發(fā)布時(shí)間:2023/12/3 javascript 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Thymeleaf 3 – Thymeleaf 3和Spring MVC快速入门 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Thymeleaf 3發(fā)布到達(dá)。 新版本帶來(lái)了許多新功能,例如HTML5支持以及不帶標(biāo)記的文本模板支持– [# th:utext="${thymeleaf.version}" /] ,改進(jìn)的內(nèi)聯(lián)功能– <p>Thymeleaf [[${thymeleaf.version}]] is great!</p> ,性能改進(jìn)等等。

使用Thymeleaf 3和Spring MVC入門的最簡(jiǎn)單方法是使用Spring MVC 4 Quickstart Maven Archetype 。 已更新原型以支持Thymeleaf3。下面將描述對(duì)原型所做的更改。

依存關(guān)系

該項(xiàng)目使用Spring Platform BOM進(jìn)行依賴關(guān)系管理,但是(在撰寫本文時(shí))尚未聲明對(duì)Thymeleaf 3的依賴關(guān)系,因此我需要手動(dòng)聲明版本。

  • 胸腺
<dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf</artifactId><version>3.0.0.RELEASE</version> </dependency>
  • Thymeleaf Spring 4:
<dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring4</artifactId><version>3.0.0.RELEASE</version> </dependency>
  • Thymeleaf Spring Security 4:
<dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-springsecurity4</artifactId><version>3.0.0.RELEASE</version> </dependency>

使用原型生成的應(yīng)用程序使用Java 8時(shí)間方言,并且由于Thymeleaf API已更改,因此方言依賴項(xiàng)也必須更新。 在Maven Central中將其可用之前,我們必須將快照存儲(chǔ)庫(kù)添加到POM:

<repository><id>sonatype-nexus-snapshots</id><name>Sonatype Nexus Snapshots</name><url>https://oss.sonatype.org/content/repositories/snapshots</url><snapshots><enabled>true</enabled></snapshots> </repository>

然后聲明依賴項(xiàng):

<dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-java8time</artifactId><version>3.0.0-SNAPSHOT</version> </dependency>

配置變更

  • 模板解析器

之前的模板解析器:

@Bean public TemplateResolver templateResolver() {TemplateResolver resolver = new ServletContextTemplateResolver();resolver.setPrefix(VIEWS);resolver.setSuffix(".html");resolver.setTemplateMode("HTML5");resolver.setCacheable(false);return resolver; }

之后的模板解析器:

@Bean public ITemplateResolver templateResolver() {SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();resolver.setPrefix(VIEWS);resolver.setSuffix(".html");resolver.setTemplateMode(TemplateMode.HTML);resolver.setCacheable(false);return resolver; }
  • 模板引擎
@Bean public SpringTemplateEngine templateEngine() {SpringTemplateEngine templateEngine = new SpringTemplateEngine();templateEngine.setTemplateResolver(templateResolver());templateEngine.addDialect(new SpringSecurityDialect());templateEngine.addDialect(new Java8TimeDialect());return templateEngine; }
  • 查看解析器:
@Bean public ViewResolver viewResolver() {ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();thymeleafViewResolver.setTemplateEngine(templateEngine());thymeleafViewResolver.setCharacterEncoding("UTF-8");return thymeleafViewResolver; }

范本

模板在該項(xiàng)目中未更改。 但是,如果要遷移實(shí)際項(xiàng)目,則可能對(duì)閱讀遷移指南感興趣。

參考文獻(xiàn)

  • Thymeleaf 3發(fā)布信息
  • Thymeleaf 3遷移指南
  • Spring MVC 4快速入門Maven原型

翻譯自: https://www.javacodegeeks.com/2016/05/thymeleaf-3-get-started-quickly-thymeleaf-3-spring-mvc.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的Thymeleaf 3 – Thymeleaf 3和Spring MVC快速入门的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。