I'm learning Spring MVC and want to create a site. The main problem is a template system. Should I use JSP / JSF / Apache FreeMarker / Thymeleaf or something else?
I saw a lot of discussion on this subject, but they are all outdated. So, I'm curious, what is fine now?
In the pursuit of comparison between FreeMarker , Thymeleaf, Groovy and Mustache, FreeMarker has the upper hand in performance. However, Thymeleaf wins the battle overall.
The default template directory is src/main/resources/templates . This is the Maven build file. The spring-boot-devtools enables hot swapping, disables template cache and enables live reloading. The spring-boot-starter-thymeleaf is a starter for building Spring MVC applications with Thymeleaf.
Template engines are used when you want to rapidly build web applications that are split into different components. Templates also enable fast rendering of the server-side data that needs to be passed to the application. For example, you might want to have components such as body, navigation, footer, dashboard, etc.
Thymeleaf is way better in my opinion because it have good underlying priciples and exploits natural behaviour of browsers. Jsp makes html hard to read, it becomes weird mixture of html and java code which makes a lot of problems in comunication between designer - developer.
The best practices for server-side rendering have shifted towards using a template engine. These get the responsibility to merge the data with the template into the actual output.
Current preferences appear to be:
JSP's and JSF are entirely different things and have become out of fashion.
The big plus for using an actual template engine is that you are forced to separate the concerns of gathering the data to present and rendering it; this separation allows you to (unit) test the templates.
Note, however, that the industry is shifting once more towards client-side rendering, where the server just returns the data as JSON-objects and the web application uses some framework like Angular, React, jQuery or Ember to build the pages.
Note on the edit: Originally the list included Velocity, but that is no longer supported by Spring.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With