我有这个课程
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 :(得分:0)
守护者无效。添加三元运算符来处理这种情况:
<td class="col_name" th:text="${alarmNotification.guardian == null ? '' : alarmNotification.guardian.name}"/>