MyBatis 注解版(五)Spring boot 注解系列 插入对象返回 id

public interface StudentMapper {
    @Insert("insert into student(name,credit_hour) value(#{name},#{creditHour})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")//加入该注解可以保持对象后,查看对象插入id
    public int insert(Student s);
    }
@Service
public class StudentService {

    @Resource
    private StudentMapper mStudentMapper;

    public int insert(Student s){
        mStudentMapper.insert(s);
        return s.getId();
    }
}

你可能感兴趣的:(mybatis)