Mybatis设置自增主键

useGeneratedKeys="true" keyProperty="id"

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

 

转载于:https://www.cnblogs.com/jpit/p/5862673.html

你可能感兴趣的:(Mybatis设置自增主键)