▶ XML 方式
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="com.anoyi.enrity.Video" >
INSERT INTO video(title, image, description, type, value, status) VALUES
(#{title}, #{image}, #{description}, #{type}, #{value}, #{status})
</insert>
▶ 注解方式
@Mapper
public interface VideoMapper {
@Insert("INSERT INTO video(title, image, description, type, value, status) VALUES(#{title}, #{image}, #{description}, #{type}, #{value}, #{status})")
@Options(useGeneratedKeys=true, keyProperty="id")
void insert(Video video);
}
获取 ID:
video.getId()