package org.springframework.data.domain;
import org.springframework.lang.Nullable;
/**
* Simple interface for entities.
*
* @param <ID> the type of the identifier
* @author Oliver Gierke
* @author Christoph Strobl
*/
public interface Persistable<ID> {
/**
* Returns the id of the entity.
*
* @return the id. Can be {@literal null}.
*/
@Nullable
ID getId();
/**
* Returns if the {@code Persistable} is new or was persisted already.
*
* @return if {@literal true} the object is new.
*/
boolean isNew();
}
实现
Persistable接口
override 这个isNew方法。如果是new,就生成insert语句,否则生成update。
Persistable接口详解
本文介绍了Spring Data中Persistable接口的基本概念及其使用方法。该接口定义了实体标识符的获取及判断实体是否为新建状态的功能,对于区分插入与更新操作至关重要。
1832

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



