Search
Duplicate

Property or field [] cannot be found on null

태그
thymeleaf
스프링부트
코드관리 게시판의 CRUD 를 다 구상하고 실행을 해보니 다음과 같이 화면 연결이 되지 않았으며, 두가지의 에러로그가 발생했다.
이는 thymeleaf 에서 html 자원을 찾지 못했다는 것인데, 아무리 찾아봐도 경로가 잘못된 부분은 존재하지 않았다.
보통 다음과 같은 경우 위와같은 에러가 발생한다.
나는 저 경우에 해당하지 않아서 다음 에러 로그를 보았다.
뭔가 저 regDate 부분이 수상했다.
list.html
<!-- 생략 --> <tr th:each="codeDetail : ${list}"> <td align="center" th:text="${codeDetail.groupCode}">${codeDetail.groupCode}</td> <td align="center" th:text="${codeDetail.codeValue}">${codeDetail.codeValue}</td> <td align="left"> <a href="read.html" th:href="|/codedetail/read?groupCode=${codeDetail.groupCode}&codeValue=${codeDetail.codeValue}|" th:text="${codeDetail.codeName}">${codeDetail.codeName}</a> </td> <td align="center" th:text="${codeDetail.sortSeq}">${codeDetail.sortSeq}</td> <td align="center" th:text="${#temporals.format(codeGroup.regDate, 'yyyy-MM-dd HH:mm')}">${codeGroup.regDate}</td> </tr> </table> <!-- jQuery 자바스크립트 라이브러리 로딩 --> <script src="/js/jQuery-2.1.4.min.js"></script> <script th:inline="javascript"> var result = [[${msg}]]; <!-- 생략 -->
HTML
복사
알고보니 codeGroupNull 이여서 발생한 문제였다. (굵은 글자로 표기해놨다.) codeGroup 은 null 이 아닐때만 regDate 를 참조할 수 있다.
따라서 이를 해결하기 위해 if 를 의미하는 ? 를 넣어주었다. 그랬더니 다음과 같이 해결되었다.

짜자잔~