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

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

Spring Boot Cache SpEL (#result) 返回 Null

Spring Boot Cache SpEL (#result) 返回 Null

哈士奇WWW 2022-07-20 16:03:45
我有一個 Spring Boot RESTful API 來接收和發送 SMS 給客戶端。我的應用程序連接到我們的本地短信服務器,并通過移動運營商接收短信并將其推送給客戶。我的應用程序運行良好。但我想通過實現緩存來優化我的應用程序。我正在使用 Spring Boot 的簡單緩存。創建新短信時我面臨一些挑戰。發送/接收的所有 SMS 都以對話的形式(每張票)并附有客戶端。所以我面臨著將客戶端保存到緩存中的困難。下面是 createClient() 片段:@Transactional@Caching(evict = {        @CacheEvict("allClientsPage"),        @CacheEvict("countClients")}, put = {        @CachePut(value = "clients", key = "#result.id", unless="#result != null"),        @CachePut(value = "clientsByPhone", key = "#result.phoneNumber", unless="#result != null")})public Client create(Client client) {    Client c = new Client();    if (client.getName() != null) c.setName(client.getName().trim());    c.setPhoneNumber(client.getPhoneNumber().trim());    /**---***/    c.setCreatedAt(new Date());    return clientRepository.save(c);}當我嘗試創建一個新客戶端時,org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'id' cannot be found on null被拋出。
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

而不是使用unless="# result! = null"使用condition="#result != null"



查看完整回答
反對 回復 2022-07-20
  • 1 回答
  • 0 關注
  • 369 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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