Optional long parameter 'id' is present but cannot be translated into a null value due to being ...

我的代码:

 
  
 
  
@CacheEvict(value = "userInfo")
@Override
public void deleteFromCache(long id) {
    logger.info("UserSVImpl.deleteFromCache()=========删除缓存中的...Id="+id);
}
private static final long serialVersionUID = 5053158293477191727L;
下面是对象信息:

@Id@GeneratedValue
private long id;

private String name;

private String pwd;

public User() {
    super();
}

报错:

java.lang.IllegalStateException: Optional long parameter 'id' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.

大意是说 如果参数是非必须的,则会赋值为null,因此参数应该是一个object,它才能接受这个null值。

而上面代码参数id 的类型 为 long,它接受不了null值。

解决办法:

将long类型换成对象类型Long,问题解决。




 
 

你可能感兴趣的:(springboot)