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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

如何:带有Thymeleaf和Spring Boot的Java 8日期和时间

發(fā)布時間:2023/12/3 java 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何:带有Thymeleaf和Spring Boot的Java 8日期和时间 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

如果您碰巧使用Spring Boot和Thymeleaf,并且需要在視圖中格式化Java 8 Date&Time對象,則可以使用thymeleaf-extras-java8time –用于Java 8 Date&Time API的Thymeleaf模塊。

向現(xiàn)有的基于Maven或Gradle的Spring Boot項(xiàng)目中添加thymeleaf-extras-java8time就像添加依賴項(xiàng)并使用模板引擎注冊新方言一樣容易。

對于Maven,將以下依賴項(xiàng)添加到現(xiàn)有的POM中:

<dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-java8time</artifactId><version>2.1.0.RELEASE</version> </dependency>

完成后,下一步就是將方言添加到模板引擎。 使用Spring Boot,您需要在應(yīng)用程序上下文中定義一個類型為org.thymeleaf.extras.java8time.dialect.Java8TimeDialect的bean。 所有類型為org.thymeleaf.dialect.IDialect bean org.thymeleaf.dialect.IDialect注入到Spring Boot的ThymeleafAutoConfiguration并自動添加到Thymeleaf的SpringTemplateEngine 。

@SpringBootApplication public class Application {@Beanpublic Java8TimeDialect java8TimeDialect() {return new Java8TimeDialect();}public static void main(String[] args) {SpringApplication.run(Application.class);} }

Java8TimeDialect是,在表達(dá)式求值期間將temporals對象作為實(shí)用程序?qū)ο筇砑拥缴舷挛摹?這意味著它可以在OGNL或SpringEL表達(dá)式評估中使用:

The time is: <strong th:text="${#temporals.format(now, 'dd/MMM/yyyy HH:mm')}">31/12/2015 15:00</strong>

temporals java.time.Temporal提供了許多實(shí)用的方法來與java.time.Temporal一起java.time.Temporal :格式化,訪問屬性和創(chuàng)建新對象。 有關(guān)GitHub上擴(kuò)展和時temporals本身檢出項(xiàng)目頁面的更多信息: thymeleaf-extras-java8time

注意 :Spring Boot和Thymeleaf項(xiàng)目設(shè)置在此博客文章中有更詳細(xì)的描述: Spring Boot和Thymeleaf與Maven

  • 本博客文章中使用的源代碼: https : //github.com/kolorobot/spring-boot-thymeleaf

翻譯自: https://www.javacodegeeks.com/2015/11/how-to-java-8-date-time-with-thymeleaf-and-spring-boot.html

總結(jié)

以上是生活随笔為你收集整理的如何:带有Thymeleaf和Spring Boot的Java 8日期和时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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