2017-03-12 3 views
0

内部のオブジェクトのプロパティへのアクセス、私はこのクラスタイメレフ - 春。別のオブジェクト

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}"/> 
関連する問題