【发布时间】:2023-01-16 19:33:19
【问题描述】:
当我加载我的应用程序页面时,我给出下一个异常
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "instructor.user.getUserEmail()" (template: "views/instructorCreate" - line 84, col 6)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method getUserEmail() on null context object
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "instructor.user.getUserEmail()" (template: "views/instructorCreate" - line 84, col 6)] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method getUserEmail() on null context object
我的版本 Thymeleaf 3.1 和 Spring 6.0.2
我的 Html + Thymeleaf 页面
<div class="mb-3 mt-3">
<label for="userEmail" class="form-label"> Email :</label>
<input id="userEmail" type="email" name="userEmail" class="form-control"
th:value="${instructor.user.getUserEmail()}" required>
<span th:errors="${instructor.user.email}"> </span>
</div>
<div class="mb-3 mt-3">
<label for="userPassword" class="form-label"> Password :</label>
<input id="userPassword" type="text" name="userPassword" class="form-control"
th:value="${instructor.user.getUserPassword()}" required>
</div>
用户获取器
public String getUserEmail() {
return userEmail;
}
教师用户领域;
@OneToOne (cascade = CascadeType.REMOVE)
@JoinColumn (name = "user_id", referencedColumnName = "user_id", nullable = false)
private User user;
如果你知道我的问题在哪里,我会感谢你
【问题讨论】:
-
好吧,显然
instructor.user是空的。现在您需要找出原因:它是否存在于数据库中?您的 JPA 注释不正确吗?您如何创建instructor的实例? -
是的,在数据库中存在,JPA 正确,在控制器中创建实例。
标签: spring-boot hibernate thymeleaf