?? Day 10: My Spring Boot Learning Journey ??
Today, I created a Spring Boot Hello World Project using Thymeleaf, taking my first step toward building dynamic web applications!
Here’s what I accomplished:
To create a Spring Boot application and implement Thymeleaf templates, follow these steps:
1. Set up your Spring Boot project:
Using Spring Initializr:
3. Under Dependencies, add:
4. Click Generate, and it will download a ZIP file of the project. Extract it and open it in your IDE (IntelliJ, Eclipse, VS Code).
Manually creating the project:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies>
2. Create a Controller to handle the views:
In src/main/java/com/example/thymeleafEG/Controller, create a Sampleprogram.java:
领英推荐
package com.example.thymeleafEG.Controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class Sampleprogram { @GetMapping("/hellos") public String hellos() { return"hellos"; } }
3. Create a Thymeleaf template:
Create a src/main/resources/templates/hellos.html file with Thymeleaf content:
<!DOCTYPE html> <html> <head> <title>Day1 springboot</title> </head> <body> <h6 th:text="'This is example for THYMELEAF'"></h6> </body> </html>
4. Run your Spring Boot Application:
In your main application class (ThymeleafEG.java):
package com.example.thymeleafEG; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ThymeleafEgApplication { public static void main(String[] args) { SpringApplication.run(ThymeleafEgApplication.class, args); } }
When the application runs successfully, it shows a massage in the console, as shown in the following figure.
5. Test the Application:
Summary of the Steps: