๐Ÿ”™๋’ค๋กœ๊ฐ€๊ธฐ

ItemController์— list ๋งคํ•‘ ์ถ”๊ฐ€

@GetMapping("/items")
public String list(Model model) {
    List<Item> items = itemService.findItems();
    model.addAttribute("items", items);
    return "items/itemList";
}

์ƒํ’ˆ ๋ชฉ๋ก ๋ทฐ(item/itemList.html)

<!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**์œผ๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.