美文网首页
Spring Data JPA getOne()和findOne

Spring Data JPA getOne()和findOne

作者: xunuo0x | 来源:发表于2017-05-16 14:08 被阅读1186次

使用getOne()获取的是一个空的对象;用findOne则可以获取想要的;
参见源码

/**
 * 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);

/**
 * 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);

相关文章

网友评论

      本文标题:Spring Data JPA getOne()和findOne

      本文链接:https://www.haomeiwen.com/subject/iljlxxtx.html