繁体   English   中英

Spring Boot Cache SpEL(#result)返回Null

[英]Spring Boot Cache SpEL (#result) Returns Null

我有一个Spring Boot RESTful API,用于接收和发送SMS到客户端。 我的应用程序连接到我们本地的SMS服务器,并通过移动运营商接收SMS并将其推送给客户端。 我的应用程序运行良好。 但是我想通过实现缓存来优化我的应用程序。 我正在使用Spring Boot的简单缓存。 创建新的SMS时,我面临一些挑战。

所有发送/接收的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

被抛出。

在此处输入图片说明

任何帮助将不胜感激。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM