Mybatis书写

Mybatis设置主键和自增

方法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>
keyProperty="id"设置主键的值。
useGeneratedKeys="true"是否自增,同时数据库也要设计好主键自增。
原文地址:https://www.cnblogs.com/codeByWei/p/10988320.html