@GetMapping("/items")
public String list(Model model) {
List<Item> items = itemService.findItems();
model.addAttribute("items", items);
return "items/itemList";
}
<!DOCTYPE HTML>
<html xmlns:th="<http://www.thymeleaf.org>">
<head th:replace="fragments/header :: header"/>
<body>
<div class="container">
<div th:replace="fragments/bodyHeader :: bodyHeader"/>
<div>
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>์ํ๋ช
</th>
<th>๊ฐ๊ฒฉ</th>
<th>์ฌ๊ณ ์๋</th>
<th></th>
</tr>
</thead>
<tbody>
<tr th:each="item : ${items}">
<td th:text="${item.id}"></td>
<td th:text="${item.name}"></td>
<td th:text="${item.price}"></td>
<td th:text="${item.stockQuantity}"></td>
<td>
<a href="#" th:href="@{/items/{id}/edit (id=${item.id})}"
class="btn btn-primary" role="button">์์ </a>
</td>
</tr>
</tbody>
</table>
</div>
<div th:replace="fragments/footer :: footer"/>
</div> <!-- /container -->
</body>
</html>
model์ ๋ด์๋ ์ํ ๋ชฉ๋ก์ธ items ๋ฅผ ๊บผ๋ด ์ํ ์ ๋ณด๋ฅผ ์ถ๋ ฅ
ํธ๋ฌ๋ธ์ํ
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Apr 08 15:04:24 GMT+09:00 2023 There was an unexpected error (type=Internal Server Error, status=500). org.hibernate.hql.internal.ast.QuerySyntaxException: i is not mapped [select i from i]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: i is not mapped [select i from i]
i is not mapped [select i from i];๋ผ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๋ค. ์ด ์๋ฌ๋ JQPL ๊ตฌ๋ฌธ์ด ์๋ชป๋๋ค๋ ๋ป์ด๋ค. repository์ ์์ฑ๋ JQPL๋ฌธ์ ๋ฌธ์ ๊ฐ ์์ผ๋ ํด๋น ์ปจํธ๋กค๋ฌ๊ฐ ํธ์ถํ๋findAll()๋ฉ์๋๋ฅผ ํ์ธํด๋ณด์public List<Item> findAll(){ return em.createQuery("select i from i", Item.class) // ^ ์ํฐํฐ ๋ช ์ด ๋๋ฝ๋์ด์๋ค. .getResultList(); }JPQL์์ ์ํฐํฐ ํด๋์ค ์ด๋ฆ์ ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ๋ค. ์ํฐํฐ ํด๋์ค ์ด๋ฆ์ Java ํด๋์ค ์ด๋ฆ๊ณผ ๋์ผํด์ผ ํ๋ค.
Item์ํฐํฐ ํด๋์ค๊ฐ ์๋ค๋ฉด JPQL ์ฟผ๋ฆฌ์์๋ **Item**์ผ๋ก ์ฌ์ฉํด์ผ ํ๋ค.