Thursday, June 9, 2016

Spring Boot and Thymeleaf : A Simple Example

What is Thymeleaf?

Thymeleaf is a modern server-side Java template engine for both web and standalone  environments.
               
Main goal of Thymeleaf is to bring elegant natural templates to your development workflow. HTML that can be correctly displayed in browsers and also work as static prototypes, allowing for stronger collaboration in development teams.

This is the new template engine and adopted by many of the projects which are looking for the alternative to JSP. It has separate module for Spring MVC integration. This helps the spring developers to use thymeleaf out of the box from their spring applications. HTML templates written in Thymeleaf still look and work like HTML.


What are the Advantages of Thymeleaf?

  • Simplicity - It is almost similar to simple HTML syntaxes
  • Internationalization support
  • Spring EL can be used

Where to put Thymeleaf templates?

The default place for templates(HTML files) is the “templates” directory available in classpath. So we need to put at least one template into src/main/resources/templates directory.


What are the steps for Spring Boot Thymeleaf integration?

There are three simple steps

1. Maven pom dependency  ( spring-boot-starter-thymeleaf )
2. Put templates in resources/templates directory
3. Controller mapping for template 


Source Code :-  

More about Thymeleaf :- http://www.thymeleaf.org/

Thanks
Chathuranga Tennakoon
chathuranga.t@gmail.com

No comments:

Post a Comment