今天学习了SpringBoot的jpa涉及到有关于查询时,getOne与findOne,稍感困惑查询一下,解释如下:
findOne返回的是一个实体对象,而getOne返回的是一个对象的指针或引用,具体详情如下图,这也显示了在使用时需要谨慎小心,防止报错
/**
* Retrieves an entity by its id.
*
* @param id must not be {@literal null}.
* @return the entity with the given id or {@literal null} if none found
* @throws IllegalArgumentException if {@code id} is {@literal null}
*/
T findOne(ID id);
/**
* Returns a reference to the entity with the given identifier.
*
* @param id must not be {@literal null}.
* @return a reference to the entity with the given identifier.
* @see EntityManager#getReference(Class, Object)
*/
T getOne(ID id);
注:学过Hibernate的程序员们可以类比一下其中的find与get方法
spring-data-jpa中findOne与getOne的区别
最新推荐文章于 2024-07-06 19:47:31 发布