From the course: Spring Web MVC 6
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Display the number of items in the cart - Spring Tutorial
From the course: Spring Web MVC 6
Display the number of items in the cart
- [Instructor] So now that we have the product details page displayed and the add to cart functionality working, we just need to ensure that this shopping cart at the top horizontal bar is updated with the total number of items in the cart. So let's fix that. Let's go to fragments.html. And if you see on line number 34, this is that section which displays the number of items in the cart. So right now, it is hardcoded to a value of six and that is what you keep seeing here in the page. So let's fix that and ensure that it is dynamically generated according to the number of items in the cart that we kept adding. To do that, let's go ahead and explore this tag on line number 36. So we don't want the six, I will get rid of this hardcoded value. And inside the span tag, I'm going to make a check using th:if. And that check will be to basically check if there is a cart attribute in the session object. So this is an…
Contents
-
-
-
-
-
-
-
Introduction to interceptors4m 38s
-
(Locked)
Add to cart use case overview1m 28s
-
(Locked)
Add and register an interceptor class3m 42s
-
(Locked)
Add repository and Controller methods3m 25s
-
(Locked)
Map attributes on the product details page8m 39s
-
(Locked)
Add a session in the interceptor6m 3s
-
(Locked)
Implement add to cart in Controller12m 39s
-
(Locked)
Display the number of items in the cart4m 4s
-
(Locked)
Error mapping pages5m 27s
-
(Locked)
Add a custom error handler8m 29s
-
-
-