2017-03-12 1 views
0

내부 객체 속성에 액세스 나는이 수업 Thymeleaf - 봄. 다른 객체

public class Guardian { 

    public Guardian() { 
     super(); 
    } 

    private Long id; 

    private String name; 
.. 
} 

public class AlarmNotification { 


    private Long id; 


    private Guardian guardian; 
} 

내 Thymeleaf 템플릿

<td class="col_name" th:text="${alarmNotification.guardian.name}"></td> 

에서이하지만

org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'name' cannot be found on null 
+0

Guardian은 AlarmNotification에서 null입니다. 이름 속성에 액세스하려면 보호자를 초기화해야합니다. – jmw5598

+0

컨트롤러에 설정되어 있습니다 –

+1

컨트롤러 코드를 추가 할 수 있습니까? – jmw5598

답변

0

보호자가 null이 예외를 얻었다. 이 경우를 처리하는 삼항 연산자를 추가하십시오.

<td class="col_name" th:text="${alarmNotification.guardian == null ? '' : alarmNotification.guardian.name}"/> 
관련 문제