스프링부트/Thymeleaf
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'username' cannot be found on null
김찰스
2022. 3. 11. 17:25
게시판 프로젝트 진행중에
타임리프에서 오류 발생
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'username' cannot be found on null
<td>홍길동</td>
이제껏 프로젝트 진행중에 게시글의 작성자를 무조건 홍길동으로만 나오도록 했었다

<td th:text="${board.user.username}">홍길동</td>
db에 저장된 username이 출력될 수 있도록 코드를 입력해주니 status 500... 그리고 위 에러발생
<td th:text="${board.user?.username}">홍길동</td>
이렇게 하니까 db에 직접 등록해준 작성자의 이름으로 출력이 됨
그러나 참조가 안되는 게시글들은 작성자가 표시되지 않음

일단 이렇게 두고 프로젝트 진행부터...