MyBatis插入成功后返回主键

  xml

    <insert id="insertForId"  useGeneratedKeys="true" keyProperty="id">

      insert into
        student(sname,sage,ssex)
      VALUES
        (s.name,s.sage,s.ssex)

    </insert>

  Mapper:

    public void insert(@Param("s")Student s);

  ServiceImp:

    Student s=new Student("小明","18","男")

    mapper.insert(s);

    System.out.println(s.getId())

原文地址:https://www.cnblogs.com/HQ0422/p/11439040.html