DEV Community

Cover image for πŸš€ Spring Boot Journey – Day 4: Building My First UI with Thymeleaf & Tailwind CSS
Ashish prajapati
Ashish prajapati

Posted on

πŸš€ Spring Boot Journey – Day 4: Building My First UI with Thymeleaf & Tailwind CSS

Welcome to Day 4 of my Spring Boot learning journey! πŸ’š

Until now, I had been testing all my REST APIs using Postman. While Postman is an excellent tool for API development and testing, it's not something that end users interact with.

So today, I took the next step toward building a real-world application by creating a web interface using Thymeleaf and Tailwind CSS.


🎯 Why Move Beyond Postman?

REST APIs are the backbone of backend development, but users don't interact with APIs directly.

Instead, they use:

  • Websites
  • Dashboards
  • Admin Panels
  • E-commerce Applications

To bridge the gap between the backend and the frontend, I integrated Thymeleaf into my Spring Boot project.


πŸ› οΈ Setting Up Thymeleaf

The first step was adding the Thymeleaf dependency to my project.

Thymeleaf is a Java template engine that allows us to create dynamic HTML pages by rendering data directly from Spring Boot.

After adding the dependency, I created a new folder named:

src
 └── main
      └── resources
            └── templates
Enter fullscreen mode Exit fullscreen mode

Every HTML page that Spring Boot renders is placed inside the templates folder.


πŸ“¦ Creating the Product Page

Instead of returning JSON responses, I created a controller that returns an HTML page.

The controller fetches all products from the database, stores them inside the Model, and passes that data to the view.

The flow now looks like this:

Browser Request

⬇️

Controller

⬇️

Service

⬇️

Repository

⬇️

MySQL

⬇️

Model

⬇️

Thymeleaf HTML Page


πŸ“„ Displaying Dynamic Data

Using Thymeleaf, I displayed all product records inside an HTML table.

Instead of hardcoding values, I used dynamic expressions to display:

  • Product ID
  • Product Title
  • Price
  • Description
  • Category

The th:each attribute made it incredibly easy to loop through every product and generate table rows automatically.

This was my first experience connecting backend data directly to the frontend.


🎨 Styling with Tailwind CSS

A plain HTML table works, but it doesn't look very attractive.

To improve the UI, I integrated Tailwind CSS using the CDN version.

With just utility classes, I created:

  • Clean table layout
  • Responsive container
  • Rounded corners
  • Hover effects
  • Modern typography
  • Better spacing
  • Shadow effects

Without writing a single line of traditional CSS, the page looked much more professional.


πŸ”„ MVC Architecture in Action

Today's project helped me understand the Model-View-Controller (MVC) pattern.

Model

Contains the data fetched from the database.

View

The Thymeleaf HTML page responsible for displaying the data.

Controller

Receives the request, fetches the data from the Service layer, and sends it to the View.

This architecture keeps the application clean, modular, and easy to maintain.


πŸ“š What I Learned Today

βœ… Thymeleaf Template Engine

βœ… MVC Architecture

βœ… Model Object

βœ… Passing Data from Controller to View

βœ… Dynamic HTML using Thymeleaf

βœ… th:each

βœ… th:text

βœ… Tailwind CSS Integration

βœ… Responsive Table Design

βœ… Rendering Database Records on a Web Page


πŸ’‘ My Biggest Takeaway

Today was an exciting milestone in my Spring Boot journey.

Until yesterday, everything existed only as APIs returning JSON responses.

Today, I transformed those APIs into an actual user interface.

Seeing data from MySQL displayed beautifully inside a browser made the application feel much closer to a real-world product.

This also showed me how Spring Boot and Thymeleaf work seamlessly together to build dynamic web applications.

The combination of Spring Boot + Thymeleaf + Tailwind CSS provides a powerful foundation for creating modern, responsive, and user-friendly applications.


πŸš€ What's Next?

In the upcoming days, I plan to:

  • Add forms to insert new products
  • Edit existing products
  • Delete products from the UI
  • Upload product images
  • Build a complete Product Management Dashboard
  • Make the interface fully responsive

The journey continues, one project at a time. πŸ’š


#SpringBootJourney Day 4

Today's Progress:

βœ” Integrated Thymeleaf

βœ” Created Templates Folder

βœ” Connected Spring Boot with HTML

βœ” Passed Data Using Model

βœ” Displayed Dynamic Product Data

βœ” Styled the UI with Tailwind CSS

From APIs to beautiful user interfacesβ€”one step closer to building complete full-stack applications. πŸš€

Top comments (0)