프로젝트를 만들면서 데이터가 없을때
" 빈 화면 그대로 보여주는게 맞는 가? "에 대해 생각해보게 되었다.
빈 화면 그대로를 보여주는 것보다는 다른 문구를 추가해주고 싶어서 관련 내용을 찾아 보았다.
<div class="todolist__sidebarpast__container__item" th:each="todoListItem,i:${noSuccessTodoList}">
<a th:href="|/todolist/${todoListItem.getRegisterDate()}|">
<div>
<div class="todolist__sidebarpast__container__item__title" th:text="${todoListItem.getRegisterDate()}">2021년 8월 15일</div>
<div class="todolist__sidebarpast__container__item__content"th:text="${todoListItem.getTitle()}">테스트</div>
<div class="todolist__sidebarpast__container__item__percentage"th:text="${todoListItem.getStatusPercentage()+'%'}">34%</div>
</div>
</a>
</div>
<div class="todolist__sidebarpast__container__noitem" th:if="${noSuccessTodoList == null} or ${noSuccessTodoList.size() == 0}">
해야할 To-do List가 없습니다.
</div>
내가 원했던 것은 List가 null일때 원하는 문구를 출력해주는 것이 였다.
비교적 간단한 방법으로 구현할 수 있었다.
Thymeleaf에서는 어처피 List가 null이면 출력 자체를 안 한다.
따라서 List가 null일때만 출력하는 문구를 출력하고 싶은 위치에 넣어 두면 된다.