Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world

Hello. This is a continuation of Let's create a TODO application in Java 1 Brief explanation of MVC.

This time, I would like to create a Controller and display the View from there.

TODO application creation link collection

1: Brief description of MVC 2: I want to make a template with Spring Initializr and make a Hello world (here and now)

Create Spring template

First, let's create a Spring template with Spring Initializr.

Screen Shot 0002-06-01 at 12.53.18.png

I will simply proceed like this.

We will add JPA and lombok in the future, but we will add them at the same time as we update, so this time only this configuration is OK!

Preparation for Build and Run

Build

Screen Shot 0002-06-01 at 14.39.14.png

When you move the cursor to the top of Intel iJ, the menu bar will appear. Press ** Build-> Build Project ** to build. It may take some time, but let's wait. At the bottom of Intel iJ, you should see something like building.

Ready to run with Edit Configurations.

↓ Press ** Run-> Edit Configurations ** from the menu bar at the top of Intel iJ. Screen Shot 0002-06-01 at 14.39.37.png

↓ Let's enter the highlighted part like this. Select Java 11 series for JRE. Screen_Shot_0002-06-01_at_14_40_01.png

TodoController creation

Next is the creation of the controller.

Make a controller according to the path below.

java:todo>src>main>java>com.example.todo>TodoController


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

@Controller //①
public class ToDoController {

    @GetMapping("/top") //②
    public String top(){
        return "top"; //③
    }
}

① Declaration of controller

You can declare this class to be a controller by doing @Controller. The description @ ~~~ is called an annotation. (It feels like a person who can call various useful things.)

②GetMapping The @GetMapping annotation processes the method directly below when a request comes to the address in the argument with Get Method of Http Method.

③ Return top.html

As it is. You can call the html file under templates by writing this (extension omitted) The return value of the class when displaying html is String.

About import

I think that import will be added automatically when you write an annotation, but if it is not done, you can also add it by pressing ** Option + Enter ** while hovering the annotation.

Write html

Todo>src>resources>templates>top.html


<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>hello world</title>
</head>
<body>

<p>hello world</p>

</body>
</html>

Let's simply output Hello world like this. The HTML file below templates can be called by writing the controller above! !!

Actually run and check

How to run

Screen Shot 0002-06-01 at 14.57.30.png

I think there is a green arrow in the upper right corner of Intel iJ, so click on it to run the project!

Then

Screen_Shot_0002-06-01_at_15_00_37.png

You should see a window like this at the bottom of the screen.

If it is Started, it has started successfully. If you get an error, try google with that sentence! (I'm in trouble because it doesn't come out quite a bit.)

Access

If you visit [localhost: 8080 / top](http: // localhost: 8080 / top), you will see hello world!

Next time, I will write the processing of the registration part.

Recommended Posts

Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
"Teacher, I want to implement a login function in Spring" ① Hello World
I tried to create a shopping site administrator function / screen with Java and Spring
Let's create a TODO application in Java 9 Create TODO display Sort by date and time + Set due date default to today's date
Let's create a TODO application in Java 11 Exception handling when accessing TODO with a non-existent ID
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
Let's create a TODO application in Java 4 Implementation of posting function
Let's create a TODO application in Java 6 Implementation of search function
Let's create a TODO application in Java 8 Implementation of editing function
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
Let's create a TODO application in Java 1 Brief explanation of MVC
Let's create a TODO application in Java 5 Switch the display of TODO
Let's create a TODO application in Java 13 TODO form validation 1: Character limit ・ Gradle update to use @Validated
I want to display images with REST Controller of Java and Spring!
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
I tried to make a talk application in Java using AI "A3RT"
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
I tried to create a Clova skill in Java
I tried to make a login function in Java
I want to transition screens with kotlin and java!
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]
Let's create a TODO application in Java 12 Processing when a request comes in with an unused HttpMethod ・ Processing when an error occurs in the server
I tried to modernize a Java EE application with OpenShift.
Let's make a calculator application in Java ~ Display the application window
I just wanted to make a Reactive Property in Java
Create a Hello World web app with Spring framework + Jetty
I want to create a Parquet file even in Ruby
I tried to make a client of RESAS-API in Java
I want to implement various functions with kotlin and java!
Hello world in Java and Gradle
Let's make a book management web application with Spring Boot part1
I want to make a button with a line break with link_to [Note]
I can't create a Java class with a specific name in IntelliJ
I want to return to the previous screen with kotlin and java!
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
I tried to make an Android application with MVC now (Java)
[Java] I want to perform distinct with the key in the object
[Wire Mock] I want to set up a stub / mock server in Java and perform E2E tests.
Let's create a TODO application in Java 3 Save temporary data in MySQL-> Get all-> Display on top
I want to develop a web application!
I tried printing a form with Spring MVC and JasperReports 2/3 (form template creation)
I tried to make a machine learning application with Dash (+ Docker) part1 ~ Environment construction and operation check ~
[iOS] I tried to make a processing application like Instagram with Swift
Java beginner tried to make a simple web application using Spring Boot
I tried to build a Firebase application development environment with Docker in 2020
Create a TODO app in Java 7 Create Header
Create a program to post to Slack with GO and make it a container
How to create a server executable JAR and WAR with Spring gradle
I want to display a PDF in Chinese (Korean) with thin reports
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
I wrote a Lambda function in Java and deployed it with SAM
[Java Spring MVC] I want to use DI in my own class
How to make an app with a plugin mechanism [C # and Java]
[Ruby] I want to make an array from a character string with the split method. And vice versa.
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished)