EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial spring boot thymeleaf
Secondary Sidebar
Spring Tutorial
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

spring boot thymeleaf

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.

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 ($ {…}). Spring boot thymeleaf is executing on asterisk expressions and model attributes.
  • Basically, spring boot thymeleaf is the 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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)

 

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- spring boot thymeleaf 

  • 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

Spring Boot Thymeleaf 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
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

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

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

EDUCBA Login

Forgot Password?

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

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

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

EDUCBA

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

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

Let’s Get Started

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

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