After creating an empty new Spring project in IntelliJ through the Spring Initializer Template: #3 Hello Spring, you should now create your first Hello World Website.
Remember that this is a step by step instruction. It does not explain all the concepts in details. This explanaition you will get from your teacher in class.
You should now have a folder and file structure that looks something like this:
If you open your src folder you will see a main and a test folder.
Delete the:
- test folder
And delete the: - mvnw and the mvnw.cmd files.
(you could leave them in the project, but since we are not going to use them we delete them for a better overview)
Now you have a project structure that looks like this:
In the demo folder create a class and call it HomeController.java.
- Right click the "demo" folder
- chose: New -> Java Class
- Name: HomeController
- Kind: Class
Create a public method called index with a return type of String, and return the string "index".
Add @Controller above the class definition and @GetMapping("/") above the method definition.
- right click resource -> template folder
- Choose: New -> html file
- Name: index
- Kind: Html 5 file
- Delete the
<meta charset="UTF-8">
tag - Add
xmlns:th="http://www.thymeleaf.org"
to the<html lang="en">
tag
Make your code look like the image above. (do your best :))
push the green start button in the upper right corner.
Open your browser and type http://localhost:8080