2
2
.
.
4
4
.
.
9
9
R
R
e
e
t
t
u
u
r
r
n
n
-
-
V
V
i
i
e
e
w
w
-
-
T
T
h
h
y
y
m
m
e
e
l
l
e
e
a
a
f
f
I
I
n
n
f
f
o
o
[
[
G
G
]
]
In this tutorial we will build simple Spring Boot Application that only has Controller that returns Thymeleaf page.
Application Schema [Results]
Spring Boot Starters
GROUP
DEPENDENCY
DESCRIPTION
Web
Spring Web
Enables @Controller, @RequestMapping and Tomcat Server.
Template Engines
Thyemeleaf
Enables Controller to return reference to Thymeleaf template index.html
P
P
r
r
o
o
c
c
e
e
d
d
u
u
r
r
e
e
Create Project: controller_returns_thymeleaf (add Spring Boot Starters from the table)
Create Package: controllers (inside package com.ivoronline.test_spring_boot)
Create Class: MyController.java (inside package controllers)
Create Thymeleaf template: index.html (inside directory resources/templates)
MyController.java
package com.ivoronline.controller_application.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
@Controller
public class MyController {
@RequestMapping("/Hello")
public String hello() {
System.out.println("Hello from Controller");
return "index";
}
}
index.html (Thymeleaf template)
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<title>Hello from Thymeleaf</title>
<p th:text="${message}"/>
index.html
http://localhost:8080/Hello
Tomcat
MyController
R
R
e
e
s
s
u
u
l
l
t
t
s
s
http://localhost:8080/Hello (Web Browser)
Console
Hello from Controller
Application Structure
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>