其他分享
首页 > 其他分享> > MyBatis插入成功后返回主键

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())

 

标签:insert,Mapper,sage,ssex,插入,Student,MyBatis,主键
来源: https://www.cnblogs.com/HQ0422/p/11439040.html