看CrudRepository接口,进去一看,说好的crud,可是怎么不见merge或update呢?
再一看save注释:
- /**
- * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
- * entity instance completely.
- *
- * @param entity
- * @return the saved entity
- */
- <S extends T> S save(S entity);
这。。。
点进去看一看有哪些实现。。。
只有SimpleJpaRepository中的实现:
- /*
- * (non-Javadoc)
- * @see org.springframework.data.repository.CrudRepository#save(java.lang.Object)
- */
- @Transactional
- public <S extends T> S save(S entity) {
- if (entityInformation.isNew(entity)) {
- em.persist(entity);
- return entity;
- } else {
- return em.merge(entity);
- }
- }

本文深入解析Spring Data JPA中CrudRepository接口的save方法,揭示其实现细节,解释为何缺少merge或update方法,并通过具体代码示例进行说明。
798

被折叠的 条评论
为什么被折叠?



