Run WEB application with Spring Boot + Thymeleaf

I had a lot of chances to fix Spring MVC, but I haven't used Boot so much, so I will move it as a review.

Constitution

Mac OS X 10.12 Java 1.8.0_92 Spring Tool Suite 3.8.4 Spring Boot 1.5.3 thymeleaf 2.1.5

Introduction

  1. DL and install Java from Oracle Official.

  2. Download and install Spring Tool Suite (hereinafter "STS") from Official.

  3. Project creation Created with STS as follows 1.png

2.png

3.png

  1. Create controller and template Create two files below 4.png

Java

SampleController.java


package com.example;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/sample")
public class SampleController {

	@RequestMapping(method = RequestMethod.GET)
	public String test(Model model) {
		model.addAttribute("name", "Kusagi API");
		model.addAttribute("get", "GET /sample");
		model.addAttribute("post", "POST /sample");
		return "sample/index";
	}

}

HTML

index.html


<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>top page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h2 th:text="${name}"></h2>
  <p th:text="${get}" /> 
  <p th:text="${post}" /> 
</body>
</html>
  1. Run the WEB application 5.png

It worked as expected 6.png

Recommended Posts

Run WEB application with Spring Boot + Thymeleaf
Start web application development with Spring Boot
[Spring Boot] Web application creation
Run LIFF with Spring Boot
Inquiry application creation with Spring Boot
Processing at application startup with Spring Boot
Implement CRUD with Spring Boot + Thymeleaf + MySQL
Implement paging function with Spring Boot + Thymeleaf
Let's make a book management web application with Spring Boot part1
Minimal configuration to run Spring Boot application on Azure Web Apps
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Spring Boot 2.3 Application Availability
Configure Spring Boot application with maven multi module
Run Scala applications with Spring Boot through Gradle
Create CRUD apps with Spring Boot 2 + Thymeleaf + MyBatis
Create a web api server with spring boot
Personal memo Run Spring Boot + Gradle web project with Codenvy (Eclipse Che)
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Generate barcode with Spring Boot
Hello World with Spring Boot
Build a WEB system with Spring + Doma + H2DB + Thymeleaf
Try using OpenID Connect with Keycloak (Spring Boot application)
Get started with Spring boot
[Tutorial] Download Eclipse → Run Web application with Java (Pleiades)
Hello World with Spring Boot!
SNS login with Spring Boot
[Java] Thymeleaf Basic (Spring Boot)
CICS-Run Java application-(4) Spring Boot application
Create Restapi with Spring Boot ((1) Until Run of App)
Spring Boot starting with Docker
Hello World with Spring Boot
Set cookies with Spring Boot
Use Spring JDBC with Spring Boot
Web application built with docker (1)
Add module with Spring Boot
Getting Started with Spring Boot
I tried to clone a web application full of bugs with Spring Boot
Create microservices with Spring Boot
Send email with spring boot
A story that stumbled when deploying a web application created with Spring Boot to EC2
Handle Java 8 date and time API with Thymeleaf with Spring Boot
The first WEB application with Spring Boot-Making a Pomodoro timer-
Until INSERT and SELECT to Postgres with Spring boot and thymeleaf
Sample web application that handles multiple databases in Spring Boot 1.5
Use thymeleaf3 with parent without specifying spring-boot-starter-parent in Spring Boot
Spring Boot application that specifies DB connection settings with parameters
[Java] Sample project for developing web applications with Spring Boot
Use Basic Authentication with Spring Boot
Spring Boot application development in Eclipse
Spring Boot application code review points
gRPC on Spring Boot with grpc-spring-boot-starter
Hot deploy with Spring Boot development
Spring Boot programming with VS Code
Until "Hello World" with Spring Boot
Get validation results with Spring Boot
Build a web application with Javalin
(Intellij) Hello World with Spring Boot
Google Cloud Platform with Spring Boot 2.0.0
Check date correlation with Spring Boot
Implement Spring Boot application in Gradle