Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What template engine should I use in Spring MVC?

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?

like image 780
Sergey Bakotin Avatar asked Jun 02 '17 03:06

Sergey Bakotin


People also ask

Which is better FreeMarker or Thymeleaf?

In the pursuit of comparison between FreeMarker , Thymeleaf, Groovy and Mustache, FreeMarker has the upper hand in performance. However, Thymeleaf wins the battle overall.

Which is the default HTML template engine in spring boot?

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.

When should I use template engine?

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.

Which is better JSP or Thymeleaf?

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.


Video Answer


1 Answers

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:

  • Thymeleaf
  • FreeMarker

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.

like image 116
McBeelen Avatar answered Sep 23 '22 13:09

McBeelen