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。