Cannot make a static reference to the non-static method findOne(Specification)……

最近在学习springboot,今天在给findOne赋值的时候,出现了以下错误

Cannot make a static reference to the non-static method findOne(Specification<XXX>) from the type JpaSpecificationExecutor<XXX>

好吧,最后发现,确实是自己活该。
原因很简单,就是忘记将函数类实例化了。举个例子:

import com.example.demo.jpa.UserJPA;

Optional<UserEntity> find = UserJPA.findOne(mtest.UserEqual());

直接这样使用,是一定会报错的,因为如果要这样使用,后面的findOne就得是静态函数才行。正确的用法是:

import com.example.demo.jpa.UserJPA;

@Autowired
private UserJPA mUserJPA;
Optional<UserEntity> find = mUserJPA.findOne(mtest.UserEqual());

没错,实例化!!!这个错误很低级,但是不知道怎么就犯了。
其实从字面上就能理解,就是无法对findOne这样的非静态函数,进行静态引用。怪只怪自己英语也不好,编程基础也不扎实。

发布了45 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/baidu_31788709/article/details/103758795