In this tutorial we will build simple Spring Boot Application that only has Controller that returns Thymeleaf page.
Application Schema [Results]
Spring Boot Starters
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}"/>