I noticed that Freemarker1 does not yet support the Java SE 8 Date and Time2. I noticed this, because I tried it. It just tries to parse the toString() and it fails.
There's already blogs about it.
So I had to add a little dependency to provide this, courtesy of Jakob Vad Nielsen3.
<dependency>
<groupId>no.api.freemarker</groupId>
<artifactId>freemarker-java8</artifactId>
<version>1.1.5</version>
</dependency>
<groupId>no.api.freemarker</groupId>
<artifactId>freemarker-java8</artifactId>
<version>1.1.5</version>
</dependency>
Of course, it's not native support, you still have to call specific methods to parse this. But it works in my case.
It means I have to change some of my templates around, as described below:
Published Date ${blog.createDate?datetime}
Instead should be:
Published Date ${blog.createDate.format()}
References
- [1] FreeMarker Java Template Engine
- https://freemarker.apache.org/
- [2] Java Technical Details - Java SE 8 Date and Time
- https://www.oracle.com/technical-resources/articles/java/jf14-date-time.html
- [3] GitHUb - Java library adding support for the Java 8 java.time api to FreeMarker.
- https://github.com/lazee/freemarker-java-8
No comments:
Post a Comment