百里香 - Spring 。访问另一个对象中的对象 属性
Thymeleaf - Spring . Accessing a object property inside another object
我有这个类
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
监护人为空。添加三元运算符来处理这种情况:
<td class="col_name" th:text="${alarmNotification.guardian == null ? '' : alarmNotification.guardian.name}"/>
我有这个类
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
监护人为空。添加三元运算符来处理这种情况:
<td class="col_name" th:text="${alarmNotification.guardian == null ? '' : alarmNotification.guardian.name}"/>