- 问题描述:
在dao.xml文件中写insert语句,keyProperty="id" useGeneratedKeys="true" 返回id不是主键
<insert id="insertBusiRiskList" keyProperty="id" useGeneratedKeys="true" > INSERT INTO `busi_risk_list` (risk_link, risk_factor, `type`) VALUES (#{riskLink}, #{riskFactor}, #{type}); </insert>
- 解决:
<insert id="insertBusiRiskList" keyProperty="id" keyColumn="id" useGeneratedKeys="true" >
INSERT INTO `busi_risk_list` (risk_link, risk_factor, `type`)
VALUES (#{riskLink}, #{riskFactor}, #{type});
</insert>
添加 keyColumn="recordId"
在实体类中也要加上此字段
pirvate Integer recordId;
insert语句执行完后,执行get方法可以获取主键,即对象.getRecordId();