Spring Boot2 Web application development with Visual Studio Code Hello World creation

Introduction

We will develop a web application for Spring Boot 2 with Visual Studio Code. This is the Spring Boot version of Hello World created earlier here.

Development environment construction

Please build the development environment by referring to here. Maven and Tomcat are not required. Add the extension "Spring Boot Extension Pack". springex.jpg

environment

OS:Windows 10 Pro 64bit Editor:Visual Studio Code 1.44.2 JDK:AdoptOpenJDK 11.0.6+10 x64

Creating a template

You can do it on Visual Studio Code, but you can also create it with spring initializr (https://start.spring.io/). This time I did it like this. springinit.jpg

Expand the created template to "D: \ JAVA \ Project".

Creating a Controller

Create it in "D: \ JAVA \ Project \ bootSample1 \ src \ main \ java \ com \ example \ bootSample1 \ web \ controller". If the folder does not exist, create it.

RootController.java

RootController.java


package com.example.bootSample1.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class RootController {

    @GetMapping("/")
    public String root() {
        // "redirect:"Prefix to redirect
        return "redirect:hello/index";
    }

}

HelloController.java

HelloController.java


package com.example.bootSample1.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/hello")
public class HelloController {

    @GetMapping("/index")
    public String indexGet() {
        return "hello/index";
    }
    
}

Create View

Create it in "D: \ JAVA \ Project \ bootSample1 \ src \ main \ resources \ templates \ hello". If the folder does not exist, create it.

index.html

index.html


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Hello World</title>
    </head>

    <body>
        <h1>Hello World</h1>
    </body>
</html>

Operation check

Press the "F5" key to execute. http://localhost:8080/ Please access. Make sure you are automatically redirected to [http: // localhost: 8080 / hello / index](http: // localhost: 8080 / hello / index).

It is OK if the following page is displayed. springbootHello.jpg

Summary

Controller and View are exactly the same as the previous non-Boot sample. The convenience of Boot is that it does not require any preparation.

Recommended Posts

Spring Boot2 Web application development with Visual Studio Code Hello World creation
Spring5 MVC Web App Development with Visual Studio Code Hello World Creation
Spring Boot2 Web application development with Visual Studio Code SQL Server connection
Spring5 MVC Web application development with Visual Studio Code Maven template creation
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 2/3 [Page creation 1/2]
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 3/3 [Page creation 2/2]
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 1/3 [Preparation]
Spring5 MVC web application development with Visual Studio Code SQL Server connection
Start web application development with Spring Boot
Hello World with Spring Boot
Hello World with Spring Boot!
[Spring Boot] Web application creation
Hello World with Spring Boot
Spring5 MVC Web application development with Visual Studio Code Environment construction (Installation of JDK11, Maven, Tomcat, Visual Studio Code)
Until "Hello World" with Spring Boot
Inquiry application creation with Spring Boot
(Intellij) Hello World with Spring Boot
Build WebAPP development environment with Java + Spring with Visual Studio Code
(IntelliJ + gradle) Hello World with Spring Boot
Run WEB application with Spring Boot + Thymeleaf
Hello world! With Spring Boot (Marven + text editor)
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Introduction to Java development environment & Spring Boot application created with VS Code
Hello World (REST API) with Apache Camel + Spring Boot 2
Build Java program development environment with Visual Studio Code
Hello World (console app) with Apache Camel + Spring Boot 2
Hello World with VS Code!
Create a Hello World web app with Spring framework + Jetty
Java web application development environment construction with VS Code (struts2)
Use PlantUML with Visual Studio Code
Spring Boot Hello World in Eclipse
Spring Boot application code review points
Hot deploy with Spring Boot development
Spring Boot programming with VS Code
Web application creation with Nodejs with Docker
Let's make a book management web application with Spring Boot part1
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
Processing at application startup with Spring Boot
[Practice! ] Display Hello World in Spring Boot
Launch Nginx + Spring Boot application with docker-compose
Java development with Codenvy: Hello World! Run
How Spring Security works with Hello World
Experience .NET 5 with Docker and Visual Studio Code
Hello World at explosive speed with Spring Initializr! !! !!
I tried to clone a web application full of bugs with Spring Boot
Try to display hello world with spring + gradle
Create Spring Boot environment with Windows + VS Code
Create a web api server with spring boot
[Jakarta EE 8 application development with Gradle] 2. Project creation
Create a Spring Boot development environment with docker
From creating a Spring Boot project to running an application with VS Code
A story that stumbled when deploying a web application created with Spring Boot to EC2
Getting started with Java programs using Visual Studio Code
Try using OpenID Connect with Keycloak (Spring Boot application)
Why can I develop Java with Visual Studio Code?
Until you start development with Spring Boot in eclipse 1
Roughly the flow of web application development with Rails.
Until you start development with Spring Boot in eclipse 2
Hello World comparison between Spark Framework and Spring Boot
Spring Boot 2.3 Application Availability
Hello World with Micronaut