using db column as img src?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

using db column as img src?

Hello people, I am new to Thymeleaf, this is only my second web application so excuse my noobness.

What I am having trouble with is I am trying to display a list of items from a "inventory" on a view and I want to use one of the columns to save URL's for image sources. So far I have it to where It will display all items saved in the table, But I am having trouble pulling out the string from the imgUrl column.

Any suggestions as to what I should try next?

			<div th:unless="${#lists.isEmpty(items)}">
				<dl th:each="item : ${items}">
				<dt class="itemInfo">	
				<span th:if="${}" th:text="${}">ID: </span> <br/>
				<span th:if="${ eq null}">No ID available</span> <br/>
				<label>Image URL:</label>

                                <!-- here is where I try to add the image -->
				<img th:src="@{item.imgUrl}"
	         		src="${item.imgUrl}" width="350" height="200"/>
				<span th:if="${item.imgUrl}" th:text="${item.imgUrl}"></span> <br/>
				<span th:if="${item.imgUrl eq null}">No image available</span> <br/>
				<span th:if="${item.size}" th:text="${item.size}">Size: </span> <br/>
				<span th:if="${item.size eq null}">No size available</span> <br/>
				<span th:if="${item.designer}" th:text="${item.designer}">Designer: </span> <br/>
				<span th:if="${item.designer eq null}">No description available</span> <br/>
				<span th:if="${item.description}" th:text="${item.description}">Description: </span> <br/>
				<span th:if="${item.description eq null}">No description available</span> <br/>
				<span th:if="${item.color}" th:text="${item.color}">Color: </span> <br/>
				<span th:if="${item.color eq null}">No color available</span> <br/>
				<span th:if="${item.type}" th:text="${item.type}">Type: </span> <br/>
				<span th:if="${item.type eq null}">No type available</span> <br/>
				<span th:if="${item.price}" th:text="${item.price}">Price: </span> <br/>
				<span th:if="${item.price eq null}">No price available</span> <br/>
				<div th:if="${#lists.isEmpty(items)}">	
				<p>You have no items in your inventory</p>

	// inventory view
	public String inventory(HttpSession session, Model model) {
		List<Item> itemList = item.findAll();
		if (itemList != null) {
			model.addAttribute("items", itemList);
		boolean hasUserRole = hasUserRole();
		boolean hasAdminRole = hasAdminRole();		
		if (hasUserRole) {
			session.setAttribute("userrole", hasUserRole);
		else if (hasAdminRole) {
			session.setAttribute("adminrole", hasAdminRole);
		return "inventory";