인프런 커뮤니티 질문&답변

twosom님의 프로필 이미지

작성한 질문수

실전! 스프링 부트와 JPA 활용2 - API 개발과 성능 최적화

조회용 샘플 데이터 입력

모든 주문리스트 조회하는 타임리프 올려봅니다.

해결된 질문

21.02.27 03:39 작성

·

513

17

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/header :: header"></head>
<body>

<div class="container">
<div th:replace="fragments/bodyHeader :: bodyHeader"></div>
<div>
<div>

<form th:object="${orderSearch}" class="form-inline">
<div class="form-group mb-2">
<input type="text" th:field="*{memberName}" class="form- control" placeholder="회원명"/>
</div>

<div class="form-group mx-sm-1 mb-2">
<select th:field="*{orderStatus}" class="form-control">
<option value="">주문상태</option>
<option th:each="status : ${T(jpabook.jpashop.domain.OrderStatus).values()}"
th:value="${status}"
th:text="${status}">option
</option>
</select>
</div>
<button type="submit" class="btn btn-primary mb-2">검색</button>
</form>


</div>
<table class="table table-striped">
<thead>
<tr>
<th>#</th> <th>회원명</th> <th>대표상품 이름</th> <th>대표상품 주문가격</th> <th>대표상품 주문수량</th> <th>상태</th> <th>일시</th>
<th></th>
</tr>
</thead>
<tbody>
<span th:each="item : ${orders}">
<tr th:each="orderItem : ${item.orderItems}">
<td th:text="${orderItem.item.id}"></td>
<td th:text="${item.member.name}"></td>
<td th:text="${orderItem.item.name}"></td>
<td th:text="${orderItem.orderPrice}"></td>
<td th:text="${orderItem.count}"></td>
<td th:text="${item.status}"></td>
<td th:text="${item.orderDate}"></td>
<td>
<a th:if="${item.status.name() == 'ORDER'}" href="#"
th:href="'javascript:cancel('+${orderItem.order.id}+')'"
class="btn btn-danger">CANCEL</a>
</td>
</tr>

</span>
</tbody>
</table>
</div>
<div th:replace="fragments/footer :: footer"></div>
</div> <!-- /container -->
</body>
<script>
function cancel(id) {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "/orders/" + id + "/cancel");
document.body.appendChild(form);
form.submit();
}
</script>
</html>

구글 뒤져가면서 왜 이중 each를 쓰는데 인텔리제이가 빨간줄 긋지...싶었는데

tr을 두번으로 each하면 안되나봅니다. ㅠㅠ

바깥의 each를 span태그로 바꿔주니까 잘되는거같네요!

혹시나 막히시는 분들은 참고하셔요!

이거 만드는데 1시간넘게걸렸네요 .. ㅠㅠㅠㅠㅠㅠ

답변 1

2

김영한님의 프로필 이미지
김영한
지식공유자

2021. 02. 27. 19:24

if0rever님

좋은 내용 공유해주셔서 감사합니다.

twosom님의 프로필 이미지

작성한 질문수

질문하기