[Practice! ] Display Hello World in Spring Boot

1. Prior knowledge

-[Even beginners can do it! ] How to install Eclipse on Windows 10 (Java environment construction)

As prior knowledge, the contents of the above link are required.

2. Preparation

01.png

  1. Start Eclipse. 02.png
  2. Select [Window (W)] → [Open Perspective] → [Other]. 03.png
  3. Select JavaEE and click the Open button. 04.png
  4. Select [Help (H)] → [Eclipse Marketplace (M) ...]. 05.png
  5. Install Spring Tools 4 (aka Spring Tool Suite 4) 4.7.0.RELEASE.

3. Create Spring Boot project

Folder structure


Hello
└─ src
     └─ main
          ├─ java
          │   └─ com
          │        └─ example
          │             └─ demo
          │                  ├─ HeloController.java
          │                  └─ HelloApplication.java
          └─ resources
               ├─ application.properties
               │  
               ├─ static
               └─ templates
                    └─ index.html

HeloController.java


package com.example.demo;

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
public class HeloController {
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {
        model.addAttribute("message", "Hello Springboot");
        return "index";
    }
}

index.html


<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <title>Hello</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <h1>Hello World</h1>
    <p>
      <span th:text="${message}"></span>!!!
    </p>
  </body>
</html>

06.png

  1. Select [File (F)]-> [New (N)]-> [Spring Starter Project]. 07.png
  2. Enter Hello as the name and click theNext>button. 08.png
  3. Select [Template Engine] → [Thymeleaf] and [Web] → [Spring Web] and click the Finish button. 09.png
  4. Right-click on com.example.demo and select[New] → [Class]. 10.png
  5. Enter HelloController in the name and click theDone (F)button. 11.png
  6. Right-click on templates and select[New] → [Other]. 12.png
  7. Select [Web] → [HTML File] and click the Next button. 13.png
  8. Enter ʻindex.html in Filename (M) and click the Done (F) `button. 14.png
  9. Right-click on Hello [boot] and select [Run] → [5 Maven install].
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.125 s
[INFO] Finished at: 2020-07-05T21:50:22+09:00
[INFO] ------------------------------------------------------------------------
  1. Success if the above statement is displayed on the console. 16.png
  2. Right-click on Hello [boot] and select [Run] → [9 Spring Boot Application]. 17.png
  3. Access [localhost: 8080](http: // localhost: 8080 /), and if it looks like the image, it is successful.

4. Related

-[Useful to remember !!!] Easy creation of constructor and getter / setter in Eclipse -[Useful to remember !!!] Easy creation of inherited class in Eclipse -[Useful to remember !!!] Change MySQL character code -[Even beginners can do it! ] How to write Javadoc -[Easy-to-understand explanation! ] How to use Java overload -[Easy-to-understand explanation! ] How to use Java encapsulation -[Easy-to-understand explanation! ] How to use Java inheritance [Override explanation] -[Easy-to-understand explanation! ] Type conversion of reference type in Java -[Easy-to-understand explanation! ] How to use Java polymorphism -[Easy-to-understand explanation! ] How to use ArrayList [Java] -[Practice! ] Introduction of JFrame (explanation up to screen creation) -[Practice! ] Java database linkage (Connector / J 8.0.20) -[Practice! ] Execution of SQL statement -All about Java programming

Recommended Posts

[Practice! ] Display Hello World in Spring Boot
Spring Boot Hello World in Eclipse
Hello World with Spring Boot
Hello World with Spring Boot!
Hello World with Spring Boot
Until "Hello World" with Spring Boot
(Intellij) Hello World with Spring Boot
Hello World with Eclipse + Spring Boot + Maven
(IntelliJ + gradle) Hello World with Spring Boot
"Hello World" in Java
Hello World in Java
Hello world! With Spring Boot (Marven + text editor)
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Try to display hello world with spring + gradle
Set context-param in Spring Boot
Hello World (REST API) with Apache Camel + Spring Boot 2
Spring Boot 2 multi-project in Gradle
Major changes in Spring Boot 1.5
NoHttpResponseException in Spring Boot + WireMock
Hello World comparison between Spark Framework and Spring Boot
Hello World (console app) with Apache Camel + Spring Boot 2
Spring Boot application development in Eclipse
Write test code in Spring Boot
Implement REST API in Spring Boot
What is @Autowired in Spring boot?
Implement Spring Boot application in Gradle
hello, world in Vanilla Java-EHW2018 "MVP"
Thymeleaf usage notes in Spring Boot
Hello world in Java and Gradle
Launch (old) Spring Boot project in IntelliJ
Build Spring Boot + Docker image in Gradle
Static file access priority in Spring boot
Hello, World! In the bootstrap loader area
Output Spring Boot log in json format
Local file download memorandum in Spring Boot
Create Java Spring Boot project in IntelliJ
"Hello, World!" With Kotlin + CLI in 5 minutes
Use DynamoDB query method in Spring Boot
How Spring Security works with Hello World
DI SessionScope Bean in Spring Boot 2 Filter
Change session timeout time in Spring Boot
Spring Boot2 Web application development with Visual Studio Code Hello World creation
"Teacher, I want to implement a login function in Spring" ① Hello World
SameSite cookie in Spring Boot (Spring Web MVC + Tomcat)
Test controller with Mock MVC in Spring Boot
Asynchronous processing with regular execution in Spring Boot
Run a Spring Boot project in VS Code
Hello World with JavaFX 11 (OpenJFX) in Liberica JDK 11
Output request and response log in Spring Boot
Hello World at explosive speed with Spring Initializr! !! !!
Read "Hello world"
Challenge Spring Boot
Use Servlet filter in Spring Boot [Spring Boot 1.x, 2.x compatible]
How to add a classpath in Spring Boot
Java, Hello, world!
Java tips-Create a Spring Boot project in Gradle
[Swift] Display Hello Swift!
Java Hello World
Spring Boot Form