[英]How to use findOne() method of CRUDRepository using Spring Boot?
I want to use the findOne()
method of CRUDRepository
, but unable to use it. 我想使用
CRUDRepository
的findOne()
方法,但是无法使用它。
I am using the CRUDRepository
for Persistence. 我正在使用
CRUDRepository
进行持久化。 I checked the CRUDRepository, but the findOne()
method is not available. 我检查了CRUDRepository,但是
findOne()
方法不可用。 When I searched Javadoc of CRUDRepository it shows findOne()
method is there. 当我搜索CRUDRepository的Javadoc时,它显示了
findOne()
方法。
@Override
public MultiplicationResultAttempt getResultById(Long resultId) {
return attemptRepository.findOne(resultId);
}
findOne
was replaced by findById()
in CRUD Repository
. 在
CRUD Repository
findById()
findOne
替换为findById()
。 See DATACMNS-944 参见DATACMNS-944
Note that findById
is not an exact replacement for findOne
, it returns an Optional
instead of null
. 请注意,
findById
不能完全替代findOne
,它返回Optional
而不是null
。
example usage: 用法示例:
@Override
public MultiplicationResultAttempt getResultById(Long resultId) {
return attemptRepository.findById(id).orElse(null);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.