📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
1. Create a Spring Boot Application
2. Add maven dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3. Create Spring MVC Controller
package net.javaguides.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HelloController {
@GetMapping({
"/",
"/hello"
})
public String hello(@RequestParam(value = "name",
defaultValue = "World", required = true) String name, Model model) {
model.addAttribute("name", name);
return "hello";
}
}
4. Thymeleaf ViewResolver Configuration
5. Create Thymeleaf Page
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
6. Run the app and demo
package net.javaguides.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringbootThymeleafHelloWorldExampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootThymeleafHelloWorldExampleApplication.class, args);
}
}
Demo
Conclusion
Learn spring boot at https://www.javaguides.net/p/spring-boot-tutorial.html.
Comments
Post a Comment
Leave Comment