gpt4 book ai didi

java - 如何修复: Exception evaluating SpringEL expression

转载 作者:行者123 更新时间:2023-12-02 02:15:57 26 4
gpt4 key购买 nike

我正在尝试保存“员工”模型,而不为其分配任何“电话”模型(oneToOne 关系)。我有一个表单,在其中我通过添加以下内容来创建员工:名字、姓氏,然后是一个下拉列表,我可以从中选择要分配的电话。每当我不选择任何内容时,index.html 页面都会抛出: 评估 SpringEL 表达式的异常:“employee.phone.getBrand() +' '+ employee.phone.getModel()”(模板:“index” - 第 31 行,col 17)

<div align="center">
<table >
<thead>
<tr>
<th>Id Employee</th>
<th>Last Name</th>
<th>First Name</th>
<th>Phone</th>
<th>Manage</th>
</tr>
</thead>
<tbody>
<tr th:each="employee: ${employeeList} ">
<td th:text="${employee.id}">Id</td>
<td th:text="${employee.lastName}">Last Name</td>
<td th:text="${employee.firstName}">First Name</td>
<td th:text="${employee.phone.getBrand() +' '+ employee.phone.getModel()} ">Brand</td>
<td>
<a th:href="@{'employee/edit/' + ${employee.id}}"><button class="btnEdit"><i class="fa fa-edit"></i></button></a>
&nbsp &nbsp
<a th:href="@{'employee/delete/' + ${employee.id}}"><button class="btnDelete"><i class="fa fa-edit"></i></button></a>
</td>
</tr>
</tbody>
</table>
</div>

我提到该对象可以在数据库中找到,并且phone_id为空。我想添加一些有电话的员工和一些没有电话的员工。输出应该是:Doe John noPhone -> 从下拉列表中未选择任何内容。Doe Jane iPhone 10s -> 已选择手机。

你有什么建议吗?

最佳答案

如果phone可以为空,请尝试使用空安全访问器?.。尝试这样的employee.phone?.getBrand()

关于java - 如何修复: Exception evaluating SpringEL expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57303966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com