This Tutorial is a quick starter for Spring Web Application using Spring Boot + ThymeLeaf, follow the below 5 easy steps to run your very first Spring Web Application in less than 5 minutes,
Step 1: Setup Spring Web Workspace using Spring Initializr
- Open IntelliJ IDE,
- Create New Project,
- Select Spring Initializr
- Select the Project SDK (I have selected Java SDK 1.8)
- Click Next,
- Select Project Type as Gradle Project
- Java Version (8 in my case)
- Select Dependencies: Spring Web and Thymeleaf
- Click Next
- Click Finish
- If IntelliJ prompts click on "Load Gradle Project"
Step 2: Create Sping Web Controller
Under src > main > java com.example.demo, create MyHelloController.java
package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class MyHelloWorldController {
@GetMapping("/hello-world")
public String greeting() {
return "helloWorld";
}
}
Step 3: Create Thymeleaf HTML Page
Navigate to src > main > resources > templates and create file helloWorld.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Spring Web + Thymeleaf - Hello World Example!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Step 4: Run the Spring Web Application
Navigate to src > main > java com.example.demo and open DemoApplication and Run the main method.
Step 5: View Results on Web Broswer
Now open any Web Brower (Safari, Chrome, Firefox, or Edge) and open URL: http://localhost:8080/hello-world
![Hello World - Spring Web and ThymeLeaf Results Hello World - Spring Web and ThymeLeaf Results](https://code2care.org/java/spring-boot-web-and-thymeleaf-hello-world-example-in-intellij-5-easy-steps/images/Hello World - Spring Web and ThymeLeaf Results.jpg)
Download this project from GitHub: https://github.com/code2care/spring-web-thymeleaf-hello-world-example/tree/main/demo
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
- How to Change Mac Date and Time using Terminal Command - MacOS
- Adding Widgets to Mac Desktop Screen on macOS Sonoma 14 - MacOS
- Task is ambiguous in root project gradle-examples. Candidates are: myTask1, myTask2 - Gradle
- Change File Created Date and Time using Mac Terminal Command - MacOS
- How to get unique values from a list in Python - Python
- Turn on Inverted Mouse Scrolling on Windows 11 on UTM on M1/M2 Mac - Windows-11
- How to make a div tag clickable - Html
- Python 3.x : How to Convert String to Bytes - Python