mapper文件:
void insert(Map<String, Object> params);
mybatis的xml如下:
<insert id="insert" parameterType="java.util.Map" useGeneratedKeys="true" keyProperty="claimID">
insert into tbl_sales_shop_claim(shopID, empID, status, expireTime, actionEmpID, actionEmpName, actionTime, createTime)
values(#{shopID}, #{empID}, #{status}, #{expireTime}, #{actionEmpID}, #{actionEmpName},
date_format(now() ,'%Y%m%d%H%i%s'),
date_format(now() ,'%Y%m%d%H%i%s'))
</insert>
其中,useGeneratedKeys="true" keyProperty="claimID",代表取得的自动生成主键claimID将作为返回值传递给insert事件的参数:
mapper.insert(params);// params中可以取得claimID,如果传递的是bean,同理