[Java] Flow from introduction of STS to confirmation of dynamic page on localhost (3/3)

Continuing from the previous session.

The article is divided into three parts. 1. Description of MVC model 2. From the introduction of STS to Japanese localization by Pleiades ** 3. From project creation to checking the page on the local host ← Now here ** It has become.

This time, it will be from creating the project to checking the page on the local host.

Creating a project

This time, create a project with Spring-Boot. If you want to create a Spring application from scratch, you have to build a lot of settings and functions yourself, but Spring-Boot will do that for you.

From the STS menu, go to File> New> Spring Starter Project. project01

In the Create Project window that appears, change the type setting from Maven to Gradle and the package from Jar to War. Gradle can choose whether the Buildship is 2.x or 3.x, but basically I think that 3.x is fine. Gradle is a system that automates builds. If you describe the build time settings in the .gradle file, the War (Jar) file will be built according to the settings. Automation systems include Maven and Ant. project02

Other than that, do not change anything and go to the next. The dependency setting screen will appear, so select Thymeleaf and Spring Web. project03

Pressing the Done button will close the compose window and return you to the first screen. After waiting for a while, the project will be created in the package explorer on the left. This time, there is no big change, so it should be called "demo". project04

Creating an HTML file

Create the HTML file to display next. But you don't have to write the code from scratch. Templates for various files are available in STS. If you open a folder called src / main / resources in the project tree, you will find a package called templates inside. Right-click on it and go to New> Other. project05

Then a window for creating a new file will be displayed. Select Web> HTML file from the window and click Next. project06

You will be taken to the screen to select the parent folder, but do not touch it and change only the file name from the default NewFile.html to index.html. Then click the Finish button. project07

Then an index.html file will be created directly under templates. All the parts necessary to display the page are written from the beginning, so let's add "Hello, World!" To be displayed. project08

Finally, right-click on the project and select Run> Spring Boot App. project09

After some logs are flowing on the console screen below, if "Started DemoApplication in xxx seconds" is displayed, the local host should have started up safely. project10

Check the page

To check the page, go to the address bar of your favorite browser http://localhost:8080 Type in. project11 You can display it properly.

If you leave the local host as it is, it will stay up, so after checking the page, press the stop button (blue circle in the image) to stop it. It doesn't matter if you press either the up or down button. project12

The above is a simple flow from introducing STS to displaying a web page. Actually, I have to add libraries and change properties, and I also need to connect to the database, so I will write about it again.

Recommended Posts

[Java] Flow from introduction of STS to confirmation of dynamic page on localhost (3/3)
From introduction to usage of byebug
[Java] Flow from source code to execution
Output of the book "Introduction to Java"
Introduction to monitoring from Java Touching Prometheus
Confirmation and refactoring of the flow from request to controller in [httpclient]
[Java] Introduction to Java
Introduction to java
[Introduction to Java] Basics of java arithmetic (for beginners)
As of April 2018 How to get Java 8 on Mac
Introduction to Java for beginners Basic knowledge of Java language ①
From Java to Ruby !!
Introduction to java command
[Introduction to Java] Handling of character strings (String class, StringBuilder class)
Since I switched from Spring Boot (Java) to Ruby on Rails, I summarized my favorite points of Rails.
Connect from Java to PostgreSQL
[Java] Introduction to lambda expressions
[Java] Introduction to Stream API
From Ineffective Java to Effective Java
[Introduction to rock-paper-scissors games] Java
Notes on building Kotlin development environment and migrating from Java to Kotlin
Summary of results of research on object orientation [Updated from time to time]
From fledgling Java (3 years) to Node.js (4 years). And the impression of returning to Java
Introduction to Scala from a Java perspective, decompiled and understood (basic)
[Introduction to Java Table of Contents] I compared Java with other languages (interpreter type, compiler type, dynamic typing, static typing)