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.
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.
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.
Other than that, do not change anything and go to the next. The dependency setting screen will appear, so select Thymeleaf and Spring Web.
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".
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.
Then a window for creating a new file will be displayed. Select Web> HTML file from the window and click Next.
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.
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.
Finally, right-click on the project and select Run> Spring Boot App.
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.
To check the page, go to the address bar of your favorite browser http://localhost:8080 Type in. 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.
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.