일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Mapper
- Mac
- 클라우드 서비스
- 자바 파일업로드
- 데이메이커
- 한줄평
- git
- missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
- 클라우드 서비스 특징
- java
- 오류
- git push
- 줄거리
- 책
- 콜미동구
- MySQL
- 동구
- 기록하는 동구
- 파이썬 웹크롤링
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- JavaScript
- spring
- 서평
- 깃
- 에러
- 자바스크립트
- 독후감
- Xcode
- Swift
- SpringBoot
- Today
- Total
인생은 속도가 아니라 방향이다
[Thymeleaf] 타임리프 반복문 처리 및 상태변수 접근(index, count) 본문
안녕하세요, 기록하는 동구입니다. 오늘은 Thymeleaf 반복문처리와 반복변수들을 사용하는법을 포스팅하겠습니다.
첫번째로 반복문 연습이니까 리스트를 던져줘야겠죠?
Controller 에 반복문을 처리하기위해서 Product를 담은 list를 view단으로 던져줍니다.
1
2
3
4
5
6
7
8
9
10
|
@GetMapping("/test/each")
public String testEach(Model model) {
List<Product> list=new ArrayList<Product>();
list.add(new Product("사과", "10000"));
list.add(new Product("배", "20000"));
list.add(new Product("포도", "30000"));
model.addAttribute("list", list);
return "testEach";
}
|
<table>
<tr>
<th>상품번호</th>
<th>상품이름</th>
<th>상품가격</th>
</tr>
<tr th:each="item, num : ${list}">
<td>[[${num.count}]]</td>
<td>[[${item.productName}]]</td>
<td>[[${item.productPrice}]]</td>
</tr>
<tr th:each="num, numStat: ${#numbers.sequence(1,5)}">
<td th:text="${'index :'+numStat.index}"></td> <!--현재 index -->
<td th:text="${'count :'+numStat.count}"></td><!--현재 count -->
<td th:text="${'first :'+numStat.first}"></td><!--첫번째 요소인지 return boolean -->
<td th:text="${'last :'+numStat.last}"></td><!--마지막번째 요소인지 return boolean -->
<td th:text="${'size :'+numStat.size}"></td><!--반복문의 크기 -->
<td th:text="${'current :'+numStat.current}"></td><!--현재 요소 -->
<td th:text="${'even : '+numStat.even}" /><!--현재반복이 짝수인 지-->
<td th:text="${'odd :'+numStat.odd}" /><!-- 현재반복이 홀수인지 -->
</tr>
</table>