[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
Hello World with Spring Boot
(Intellij) Hello World with Spring Boot
(IntelliJ + gradle) Hello World with Spring Boot
[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
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
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
"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
"Teacher, I want to implement a login function in Spring" ① Hello World
Java, Hello, world!
Java tips-Create a Spring Boot project in Gradle
Java Hello World
Spring Boot Form
How to bind to property file in Spring Boot
Spring Boot Memorandum
gae + spring boot
Annotations used in Spring Boot task management tool
View the Gradle task in the Spring Boot project
Customize the display when an error such as 404 Not Found occurs in Spring Boot
How to use CommandLineRunner in Spring Batch of Spring Boot
Test field-injected class in Spring boot test without using Spring container
Until you start development with Spring Boot in eclipse 1
[Introduction] Display Android Studio Hello World on the emulator
Try gRPC in Spring Boot & Spring Cloud project (Mac OS)
Introduce swagger-ui to REST API implemented in Spring Boot
Until you start development with Spring Boot in eclipse 2
Specify spring.profiles.active via context-param of web.xml in Spring Boot
SerializationException in Spring Boot (1 series) + spring-security-oauth2 + Redis Session + Heroku
Database environment construction with Docker in Spring boot (IntellJ)
Spring Boot learning procedure
Studying Java-Part 1-Hello World
Learning Spring Boot [Beginning]
Microservices in Spring Cloud
Spring boot memo writing (2)
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Hello World on WebAssembly
Spring boot tutorials Topics
Get cookies in Spring
Hello World with Micronaut
Download with Spring Boot
How to call and use API in Java (Spring Boot)
Get error information using DefaultErrorAttributes and ErrorAttributeOptions in Spring Boot 2.3
Use thymeleaf3 with parent without specifying spring-boot-starter-parent in Spring Boot
Until Android Studio beginners display "Hello World" on HUAWEI nova 2