Spring boot ThymeleafでJSR 310: Date and Timeを使う
Spring徹底入門のチュートリアルを始めたんですが、いきなり
JSR 310: Date and Time APIのクラスを使用するからライブラリとクラスを追加してねと
。。。。
えっとなにそれ?
http://acro-engineer.hatenablog.com/entry/20130213/1360691391
なるほど
java.util.Dateが使いづらいので作られたJoda TimeというOSSのライブラリの発想をパクって参考にしてJava8にも似たような機能が実装されたんですな。
ViewとしてThymelieafでDate and Timeクラスを扱うことが出来ないのでThymeleafから提供されているthymeleaf-extras-java8timeを使う必要があるんだとか
ここですね。
https://github.com/thymeleaf/thymeleaf-extras-java8time
groupId: org.thymeleaf.extras
artifactId: thymeleaf-extras-java8time
バージョンは
Version 3.0.0.RELEASE - for Thymeleaf 3.0 (requires Thymeleaf 3.0.0+)
Version 2.1.0.RELEASE - for Thymeleaf 2.1 (requires Thymeleaf 2.1.3+)
build.gradleの
で良いみたいです。
しかし設定にバージョン入れるのゲフンゲフン
後は
って感じでBeanを作ってやれば良いらしい。
(追記)
ある程度写経が進んだところで起動してみたら
Caused by: java.lang.ClassNotFoundException: org.thymeleaf.dialect.IExpressionObjectDialect
ってエラーに
ググってみると
http://ksby.hatenablog.com/?page=1487513133
build.gradleでバージョン指定をやめればよさそうです。
compile('org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.0.RELEASE')
↓
compile('org.thymeleaf.extras:thymeleaf-extras-java8time')
だからバージョン指定とか(ry
編集してから再起動したら問題なし
JSR 310: Date and Time APIのクラスを使用するからライブラリとクラスを追加してねと
。。。。
えっとなにそれ?
http://acro-engineer.hatenablog.com/entry/20130213/1360691391
なるほど
java.util.Dateが使いづらいので作られたJoda TimeというOSSのライブラリの発想を
ViewとしてThymelieafでDate and Timeクラスを扱うことが出来ないのでThymeleafから提供されているthymeleaf-extras-java8timeを使う必要があるんだとか
ここですね。
https://github.com/thymeleaf/thymeleaf-extras-java8time
groupId: org.thymeleaf.extras
artifactId: thymeleaf-extras-java8time
バージョンは
Version 3.0.0.RELEASE - for Thymeleaf 3.0 (requires Thymeleaf 3.0.0+)
Version 2.1.0.RELEASE - for Thymeleaf 2.1 (requires Thymeleaf 2.1.3+)
build.gradleの
dependencies {
compile('org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.0.RELEASE')
}
で良いみたいです。
しかし設定にバージョン入れるのゲフンゲフン
後は
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect;
@Configuration
public class ThymeleafConfig {
@Bean
public Java8TimeDialect java8TimeDialect() {
return new Java8TimeDialect();
}
}
って感じでBeanを作ってやれば良いらしい。
(追記)
ある程度写経が進んだところで起動してみたら
Caused by: java.lang.ClassNotFoundException: org.thymeleaf.dialect.IExpressionObjectDialect
ってエラーに
ググってみると
http://ksby.hatenablog.com/?page=1487513133
build.gradleでバージョン指定をやめればよさそうです。
compile('org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.0.RELEASE')
↓
compile('org.thymeleaf.extras:thymeleaf-extras-java8time')
だからバージョン指定とか(ry
編集してから再起動したら問題なし
この記事へのコメント