使用注解:@Options(useGeneratedKeys=true,keyColumn=“id”)
package mapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import entity.R;
@Mapper
public interface RMapper {
@Insert("INSERT INTO r (name) VALUES (#{name})")
@Options(useGeneratedKeys=true,keyColumn="id")
public Integer save(R r);
}
本文介绍如何使用MyBatis的注解@Options和@Insert来实现实体类在插入数据库时ID自动生成。通过具体代码示例,展示如何在Mapper接口中配置这些注解以达到自增ID的效果。
2315

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



