首先按照以下语法编写,主要加入了keyProperty="id" useGeneratedKeys="true"。
1. <insert id="insertPersonManage" keyProperty="id" useGeneratedKeys="true"> 2. insert into organization_manager_info( 3. orgId, appointStatus, empId, mantPeriod, isOrgRight, isOrgIndeRight,isPostRight,isPostIndeRight, 4. isManagerRight, isMangerIndeRight, isTransferRight, isTransferIndeRight,detail, addPeople )values( 5. #{orgId},#{appointStatus} , #{empId}, #{mantPeriod}, #{isOrgRight}, #{isOrgIndeRight},#{isPostRight},#{isPostIndeRight}, 6. #{isManagerRight} ,#{isMangerIndeRight} , #{isTransferRight}, #{isTransferIndeRight},#{detail}, #{addPeople}) 7. </insert>
keyProperty="id" useGeneratedKeys="true"
然后在入参的VO中获取就可以了
1. public void insertPersonManage(OrganizationManagerInfoBO organizationManagerInfoBo){ 2. personInChargeManage.insertPersonManage(organizationManagerInfoBo); 3. //获取自增ID 4. Long id = organizationManagerInfoBo.getId(); 5. //如果直接生成的正常状态 那么在日志表生成一条新记录 6. if(FROMAL.equals(organizationManagerInfoBo.getAppointStatus())){ 7. OrganizationManagerInfoBO logOrganizationManagerInfoBo = new OrganizationManagerInfoBO(); 8. //原表数据转换到日志表中 9. BeanUtils.copyProperties(organizationManagerInfoBo,logOrganizationManagerInfoBo); 10. logOrganizationManagerInfoBo.setOrgManagerInfoId(id); 11. } 12. }