MyBatis 3.2.6插入时候获取自增主键方法

MyBatis 3.2.6插入时候获取自增主键方法有二ide

 

以MySQL5.5为例:it

 

方法1:ast

    <insert id="insert" parameterType="Person" useGeneratedKeys="true" keyProperty="id">
        insert into person(name,pswd) values(#{name},#{pswd})
    </insert>class

 

方法2:select

    <insert id="insert" parameterType="Person">
        <selectKey keyProperty="id" resultType="long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into person(name,pswd) values(#{name},#{pswd})
    </insert>方法

 

插入前实体id属性为0;技术

插入后实体id属性为保存后自增的id;di

Face your past without regret. Handle your present with confidence.Prepare for future without fear. keep the faith and drop the fear. 面对过去无怨无悔,把握如今充满信心,备战将来无所畏惧。保持信念,克服恐惧!一点一滴的积累,一点一滴的沉淀,学技术须要不断的积淀!
相关文章
相关标签/搜索