mysql mybatis返回插入的主鍵id
[html]
<insert id="insertCompanyInfo" parameterType="com.yjf.entity.TCompanyInfo" >
insert into T_Company_Info (Company_Id, IsFranchisee, Company_Code, Company_Name)
values (#{companyId}, #{isfranchisee}, #{companyCode}, #{companyName})
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="companyId" >
SELECT LAST_INSERT_ID() AS ID
</selectKey>
</insert>
www.2cto.com
在執行插入之後執行,查詢到 主鍵id
[html]
SELECT LAST_INSERT_ID() AS ID
通過對象 com.yjf.entity.TCompanyInfo.companyId 取得主鍵
[java]
company.getCompanyId()