inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 MVC 2편 - 백엔드 웹 개발 활용 기술

반복

odd, even

1750

면류관받는날까지#
0

기존 소스코드에 나와있기는 한 부분 입니다.

다만 타임리프의 even(짝수), odd(홀수)를 true, false로

나타내는 부분에서 헷갈리는 부분이 있었기 떄문에

index의 짝수 홀수인지, count의 짝수 홀수인지에 대해

글을 작성합니다~~!! ㅎㅎ

 

답은 화면에 찍혀있는 그대로 입니다.

${userStat.count}

index가 아닌~~~~ 

count가 홀수인지 짝수인지를 판별하여서

짝수라면even은 true , odd 가 true

홀수라면 even은 false, odd는 false가 나오고 있습니다.


1) 컨트롤러 파일

private void
addUsers(Model model){

List<User> list = new ArrayList<>();
list.add(new User("userA", 10));
list.add(new User("userB", 20));
list.add(new User("userC", 30));
list.add(new User("userD", 40));
list.add(new User("userE", 50));


model.addAttribute("users", list);

}
 

2) 타임리프 파일

<table
border="1">
<tr>
<th>index</th>
<th>count</th>
</tr>
<tr th:each="user, userStat : ${users}">
<td th:text="${userStat.index}">0</td>
<td th:text="${userStat.count}">0</td>
<td>
index = <span th:text="${userStat.index}"></span>
count = <span th:text="${userStat.count}"></span><br />
even(짝수인가)? = <span th:text="${userStat.even}"></span><br />
odd(홀수인가)? = <span th:text="${userStat.odd}"></span>
</td>
</tr>
</table>

이렇게 넣어서 확인해 보았습니다, 

thymeleaf_odd thymleaf_even

답변 1

0

김영한

면류관받는날까지님 공유 감사합니다^^