/** * Returns a single entity matching the given {@link Example} or {@literal null} if none was found. * * @param example must not be {@literal null}. * @return a single entity matching the given {@link Example} or {@link Optional#empty()} if none was found. * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the Example yields more than one result. */ <S extends T> Optional<S> findOne(Example<S> example); /** * 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) * @throws javax.persistence.EntityNotFoundException if no entity exists for given {@code id}. */ T getOne(ID id);
findone:返回实体的optional对象java
getone:返回实体的引用,代理对象spring
实体转json的过程当中会出错,用debug查看实体实际上是空,数据是放在代理对象中的,但jackson将实体转json没有拿到代理对象,而后产生如下错误,这时候json转换失败再致使输出流报错。json
getOne示例:ide