【发布时间】:2019-08-01 07:35:39
【问题描述】:
我正在尝试保存“员工”模型而不为其分配任何“电话”模型(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>
   
<a th:href="@{'employee/delete/' + ${employee.id}}"><button class="btnDelete"><i class="fa fa-edit"></i></button></a>
</td>
</tr>
</tbody>
</table>
</div>
我提到该对象可以在 DB 中找到,并且 phone_id 为空。我想添加一些有电话的员工和一些没有电话的员工。 输出应该是: Doe John noPhone -> 从下拉列表中未选择任何内容。 Doe Jane iPhone 10s -> 已选择手机。
你有什么建议吗?
【问题讨论】: