亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復:評估 SpringEL 表達式時出現異常

如何修復:評估 SpringEL 表達式時出現異常

江戶川亂折騰 2023-05-10 13:53:07
我正在嘗試保存“員工”模型而不為其分配任何“電話”模型(oneToOne 關系)。我有一個表格,我在其中通過添加以下內容來創建員工:名字,姓氏,然后是一個下拉列表,我可以從中選擇一個電話來分配它。每當我不選擇任何東西時,index.html 頁面都會拋出:Exception evaluating SpringEL expression: "employee.phone.getBrand() +' '+ employee.phone.getModel()" (template: "index" - line 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 -> nothing selected from dropdown list. Doe Jane iPhone 10s -> 手機已選中。你有什么建議嗎 ?
查看完整描述

1 回答

?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

如果 phone 可以為 null,請嘗試使用 null-safe accessor ?.。嘗試這樣的事情employee.phone?.getBrand()



查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 208 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號