Hello World application in spring boot using controller and thymeleaf

Hello, World is one of the first application we always refer whenever we start learning any programming language or any concept and spring is no different, In the article, we will show you how to create simple Hello World application in Spring boot using Spring MVC and Thymeleaf page.

hello world using spring boot and thyemleaf


We need to simply create a hello world program in spring boot using spring MVC and Thymeleafpage.


To Achieve this we will first create the Spring boot application using start.spring.io

Now follow below code snippet.

Dependencies used

Spring Web Starter

Thymeleaf Starter

Implementation Strategy

We will first create one controller as HelloWorldController ( which is a spring MVC Controller ).

Then we will create one Thymeleaf Page where we are basically showing Welcome To Spring Boot Project.

We will connect both the Controller to View.

Also Read : Top 5 Spring boot Courses for Developers

Implementation( You can download the Project from GitHub)

The Project Structure

Hello World Project Structure

Lets start from the pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


  <description>Hello World Spring boot </description>

    <relativePath /> <!-- lookup parent from repository -->





Now let see the Controller class

package in.learnspringboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

public class HelloWorldController {
//	url to access this contoller is 
//	http://localhost:8080/home
  public String doHome( @RequestParam(value="name",required = false) String name,Model model) {
    if(name!=null ) {
      model.addAttribute("name", name);
    }else {
      model.addAttribute("name", "Spring boot User");
    return "index";


In above code


Enables class to be Controller class

@GetMapping : this annotation is used for Get Request and the request mapping to home controller
@RequestParam : this annotation is for the QueryParam value to get from the url

Now we will see the HTML file

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<meta charset="ISO-8859-1">
<p>Welcome to Spring boot Project , <span th:text="${name}"/></p>

Here th:text=${name} this basically fetch the data from the model attribute set in the controller.

Points to remember

  1. In Spring MVC when we call the Thymeleaf page, we basically call the URI of the Controller which is of Get type which will then call the view.
    1. The view of the always stored in template folder
    2. there is one another folder called static which is used for images and other static files.

Let see how to call the html page.





This first case the result will be Welcome to Spring boot Project , vishal

In Second Case the Result will be

Welcome to Spring boot Project , Spring Boot User

Hope this will help you in writing your first hello world spring boot application.


You may also like...

3 Responses

  1. Kunal says:

    Very well explained, it is an apt example for thymleaf integration with Spring Boot.

    Only 1 small change is needed in index.html, we need to give an end tag, maybe it was an issue with my app.


    Welcome to Spring boot Project ,

  1. August 30, 2018

    […] Also Read: Hello World application in spring boot using controller […]

  2. November 15, 2018

    […] Hello World application in spring boot using controller and thymeleaf […]

Leave a Reply

Your email address will not be published. Required fields are marked *