部分代码如下:
<!-- useGeneratedKeys:使用自增,keyproperty:与之配套使用,这里是user的主键 -->
<insert id="InsertUser" parameterType="com.otheima.mybatis.pojo.User" useGeneratedKeys="true" keyProperty="id" >
<!-- selectkey:主键返回;keyproperty:user中的主键类属性;resulttype:主键数据类型
order:指定selectkey何时执行
-->
<!-- <selectKey keyProperty="id" resultType="int" order=" AFTER">
select last_insert_id()
</selectKey>
-->
insert into user
(
username,
birthday,
sex,
address)
values
(
#{username},
#{birthday},
#{sex},
#{address}
)
</insert>