第一种:
<insert id="addUserForId" useGeneratedKeys="true" keyProperty="userId" parameterType="User">
insert into user(userName,password,comment)
values(#{userName},#{password},#{comment})
</insert>
第二种:
<!-- 插入一个商品 -->
<insert id="insertProduct" parameterType="domain.model.ProductBean" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="productId">
SELECT LAST_INSERT_ID()
</selectKey>
INSERT INTO t_product(productName,productDesrcible,merchantId)values(#{productName},#{productDesrcible},#{merchantId});
</insert>