Thymeleaf

spring-boot-template

https://spring.io/blog/2012/10/30/spring-mvc-from-jsp-and-tiles-to-thymeleaf/
http://www.thymeleaf.org/
http://blog.codeleak.pl/2014/04/how-to-spring-boot-and-thymeleaf-with-maven.html
https://github.com/rwinch/spring-modern-templating/blob/master/spring-modern-templating.pdf

See the Memory Game folder as well.

What are the benefits / features of using Thymeleaf?

  1. Better handling of escaping and avoid security issues
  2. Better handling of idiosyncrasies of HTML5 and XML
  3. Natural templating (friendly for designers): If you open a .jsp file directly in the browser (directly via the file system instead of going through a web server), we get a hot mess, but if we open a Thymeleaf .xhtml file, we get something close to the live page. This is friendly for designer to work.

What are some differences between Thymeleaf and JSP?

Thymeleaf uses attributes almost exclusively, in sharp contrast to JSP relying on elements. And it consistently does the right thing for escaping text. The natural templating works primarily by supplying an optional placeholder and using Thymeleaf attributes, conventionally namespace-prefixed with th:, to replace that with a dynamic value at runtime. Other measures are in place for repetitive data such as tables.

<h1 th:text="${myTitle}">Title goes here</h1>

I have reservations about relying on this approach very much. For things like localized text, the placeholders end up being a lot of duplication. You can easily end up changing the placeholders rather than the real data by mistake, or letting the two get out of sync. For something like an image or stylesheet URL, your placeholder needs to be a relative path in your project, which is annoying and again can get out of sync. Furthermore, you can edit a page and reload it without restarting the entire servlet, so working on the live page really isn’t that big a pain. So, basically, I’m not sure the extra work to make natural templating usable for offline design is worth it.

What is Thymeleaf based on?

Thymeleaf defines itself as an XML / XHTML / HTML5 template engine. It is not based on JSPs but rather on some plain HTML files with a little bit of namespace magic.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License