EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign up
Home Software Development Software Development Tutorials Spring Tutorial spring boot thymeleaf

spring boot thymeleaf

Updated March 29, 2023

spring boot thymeleaf

Introduction to spring boot thymeleaf

Spring boot thymeleaf is nothing but the open-source library, which was licensed under the license of Apache 2.0; it is also known as the XHTML, XML, and HTML5 engine. It is  the server-side template engine of java; it is used in both applications, like web-based and non-web-based. Thymeleaf is perfect for web development of JVM HTML5; thymeleaf provides good integration with the framework of spring. We can apply spring boot thymeleaf on the template file to display the text or data which was produced by our application.

ADVERTISEMENT
Popular Course in this category
SPRING BOOT Course Bundle - 5 Courses in 1 | 6 Mock Tests

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

What is spring boot thymeleaf?

  • The main goal of spring boot thymeleaf is to provide a well-formed and stylish way to create the template.
  • It is based on the attributes and XML tags. The XML tags will define the document object model’s predefined and execution logic (DOM) instead of writing the logic as code.
  • We have using Thymeleaf instead of using JSP. This is because the architecture of Thymeleaf allowed the template to fast processing, which was depends on caching of parsed files.
  • It uses the possible amount of I/O operation during the execution of the project.
  • As we know that JSP is similar to HTML. But JSP is not compatible with HTML like as thymeleaf.
  • We can also open and display the template of the thymeleaf file template using the browser at while the JSP file doesn’t display the thymeleaf file.
  • It supports the variable expressions as ($ {…}). It is executing on asterisk expressions and model attributes.
  • Basically,it  is a  java based library which was used to create the web application.
  • Below are the spring boot thymeleaf version available are as follows.

Thymeleaf version

Different thymeleaf versions are mentioned below:

  • Thymeleaf 1.0 –
  1. Thymeleaf 1.0.1
  2. Thymeleaf-spring3 1.0.1
  • Thymeleaf 1.1 –
  1. Thymeleaf 1.1.5
  2. Thymeleaf-spring3 2.0.21
  • Thymeleaf 2.0 –
  1. Thymeleaf 2.0.21
  2. Thymeleaf-spring3 2.0.21
  3. Thymeleaf-spring4 2.0.21
  • Thymeleaf 2.1 –
  1. Thymeleaf 2.1.6
  2. Thymeleaf-spring3 2.1.6
  3. Thymeleaf-spring4 2.1.6
  • Thymeleaf 3.0 –
  1. Thymeleaf 3.0.12
  2. Thymeleaf-spring3 3.0.12
  3. Thymeleaf-spring4 3.0.12
  4. Thymeleaf-spring5 3.0.12
  • It is very good suited for XHTML and HTML5 at the view layer and MVC-based application.
  • Thymeleaf will process any of the XML files even if the environment is offline. Thymeleaf is providing the full integration with spring boot.

Create application

  • Below steps shows to create thymeleaf application using spring initializer are as follows.
  • We have to create the thymeleaf application using the following ways.
  1. Using spring initializer
  2. Using spring tool suite

The below steps shows create an application using a spring initializer.

  • Create a new project template using a spring initializer and give the following name to the project metadata.

Group – com.example
Artifact name – spring-boot-thymeleaf
Name – spring-boot- thymeleaf
Description – Project of spring-boot- thymeleaf
Package name – com.example.spring-boot- thymeleaf
Packaging – Jar
Java – 11
Dependencies – spring web, thymeleaf.

 

spring boot thymeleaf output 1

  • After generating project extract files and open this project by using the spring tool suite

In this step, we have to extract the zip file and opening the thymeleaf project in spring too suite.

spring boot thymeleaf output 2

  • After opening the project using the spring tool suite, check the project and its files –

After opening the project, we have to check all the project files. We need to check the java main and pom.xml files.

spring boot thymeleaf output 3

Below steps shows create an application using the spring tool suite –

  • Select the spring starter project –

spring boot thymeleaf output 4

  • Set the name and other parameters of the project –

Group – com.example
Artifact name – springbootthymeleaf
Name – spring-boot- thymeleaf
Description – Project of springbootthymeleaf
Package name – com.example.springbootthymeleaf

spring boot thymeleaf output 5

  • Select the template engine as thymeleaf –
Template engine – thymeleaf

spring boot thymeleaf output 6

  • Check the project files.

output 7

Thymeleaf Templates

  • Thymeleaf is processing six types of templates are as follows. Thymeleaf is converting our files into the well-formed XML files.
  1. HTML5
  2. XHTML
  3. Valid XHTML
  4. XML
  5. Legacy HTML5
  6. Valid XML
  • Above all, thymeleaf templates will prefer the xml files excepting the legacy HTML5. However, legacy HTML5 templates will allow rendering to HTML5 tags.
  • We can use thymeleaf templates to create a web application using spring boot.

Project explorer

  • Below is the snapshot of project explorer using thymeleaf application are as follows.
  • The below project explorer snapshot shows the main/java and JRE system library.

output 8

  • The below project explorer snapshot shows maven dependency.

output 9

  • The below project explorer snapshot shows src, test, and pom.xml files.

output 10

 Example

The below example shows thymeleaf are as follows. The below steps shows to create an application by using thymeleaf.

  • Add the thymeleaf dependency in the pom.xml file –

Code –

<dependency>   -- Start of dependency tag.
<groupId>org.springframework.boot</groupId>  -- Start and end of groupId tag.
<artifactId>spring-boot-starter-thymeleaf</artifactId>  -- Start and end of artifactId tag.
</dependency>   -- End of dependency tag.

output 11

  • Create web controller class for the project –

In this step, we have to create the web controller class for our project as bellows.

Code –

public class WebController {
@RequestMapping(value = "/index")
public String index() {
return "index";
}
}

output 12

  • Add the following dependency in build.graddle file –

Code –

@SpringBootApplication
public class springBootThymeleaf {
public static void main(String[] args) {
SpringApplication.run (springBootThymeleaf.class, args);
} }

output 13

  • Clean and build the project –

In this step, we have cleaning and building the project using maven clean and build on spring tool suite.

output 14

  • After cleaning and building the project, now hit the below URL in the web browser.

http://localhost:8080/index

output 15

Conclusion

The main goal of thymeleaf is to provide a well-formed and stylish way to create the template. Thymeleaf is nothing but the open-source library, which was licensed under the license of Apache 2.0; it is also known as the XHTML, XML, and HTML5 engine.

Recommended Articles

This is a guide to spring boot thymeleaf. Here we discuss What is spring boot thymeleaf along with the examples and codes. You may also have a look at the following articles to learn more –

  1. Spring Boot Batch
  2. Spring Boot HTTPS
  3. Spring Boot Microservices
  4. Spring Boot DevTools
ADVERTISEMENT
MICROSOFT POWER BI Course Bundle - 8 Courses in 1
34+ Hours of HD Videos
8 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
CYBER SECURITY & ETHICAL HACKING Course Bundle - 13 Courses in 1 | 3 Mock Tests
64+ Hours of HD Videos
13 Courses
3 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
KALI LINUX Course Bundle - 6 Courses in 1
20+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
  • Blog as Guest
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Cyber Monday Reloaded Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW