I am using spring configure to store and show that stored image at the view level. when user search product , show the product with image and name but my case it only show the product name and product price but not showing the image of the products webconfig.kt
package com.nilmani.cmsshopingcart
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@Configuration
class WebConfig : WebMvcConfigurer {
override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
registry
.addResourceHandler("/media/**")
.addResourceLocations("file:/C:/Users/shyamal/Downloads/cms-shopping-cart/src/main/resources/static/media/")
}
}
product index.html
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="/fragments/head"></head>
<body>
<nav th:replace="/fragments/nav :: nav-admin"></nav>
<div class="container">
<h1 class="display-2">Pages</h1>
<a href="/admin/products/add" class="btn btn-primary mb-5">Add new</a>
<!--suppress ThymeleafVariablesResolveInspection -->
<div th:if="${message}" th:text="${message}" th:class="${'alert ' + alertClass}"></div>
<div th:if="${!products.isEmpty()}">
<table class="table sorting" id="pages">
<tr class="home">
<th>Name</th>
<th>Image</th>
<th>Category</th>
<th>Price</th>
</tr>
<tr th:each="product : ${products}">
<td th:text="${product.name}"></td>
<td>
<img style="width:120px;" th:src="@{'/media/' + ${product.image}}">
</td>
<td th:text="${cats[__${product.categoryId}__]}"></td>
<td th:text="${product.price}"></td>
<td><a th:href="@{'/admin/products/edit/' + ${product.id}}">Edit</a></td>
<td><a th:href="@{'/admin/pages/delete/' + ${product.id}}" class="confirmDeletion">Delete</a></td>
</tr>
</table>
</div>
<nav class="mt-3" th:if="${count > perPage}">
<ul class="pagination">
<li class="page-item" th:if="${page > 0}">
<a th:href="@{${#httpServletRequest.requestURI} + '?page=__${page-1}__'}" class="page-link">Previous</a>
</li>
<li class="page-item" th:each="number :${#numbers.sequence(0,pageCount - 1)}"
th:classappend="${page==number} ? 'active' : ''">
<a th:href="@{${#httpServletRequest.requestURI} + '?page=_${number}'}"
class="page-ling" th:text="${number+1}"></a>
</li>
<li class="page-item" th:if="${page < pageCount -1}">
<a th:href="@{${#httpServletRequest.requestURI} + '?page=__${page+1}__'}" class="page-link">Next</a>
</li>
</ul>
</nav>
<div th:unless="${!products.isEmpty()}">
<h4 class="display-4">There are no pages at the moment</h4>
</div>
</div> <!-- /container -->
<div th:replace="/fragments/footer"></div>
</script>
</body>
</html>