mybatis 插入数据并返回主键值

<insert id="insert" parameterType="com.pojo.TSubject" useGeneratedKeys="true"  keyProperty="subjectid" > 
insert into t_subject ( parentid, subjectname, subjecttype, subjectitem, subjectanser, displaytype) values ( #{parentid,jdbcType
=INTEGER}, #{subjectname,jdbcType=VARCHAR}, #{subjecttype,jdbcType=VARCHAR}, #{subjectitem,jdbcType=VARCHAR}, #{subjectanser,jdbcType=VARCHAR}, #{displaytype,jdbcType=VARCHAR})

</insert>
useGeneratedKeys="true"  keyProperty="subjectid"
“subjectid”表主键
subjectService.insert(tSubject);
插入成功后:tSubject..getSubjectid() 就可以得到刚刚插入记录主键id

posted on 2016-06-21 10:15  lvlv岁月流逝  阅读(1028)  评论(0编辑  收藏  举报

导航