mybatis实现新添加一条数据,并获取新添加数据的ID

insert intosys_role(sr_name,sr_stats,sr_describe,um_id,sr_create_time,sr_type)values(#{srName},0,#{srDescribe},#{umId},#{srCreateTime},#{srType})通过返回值是获取不到新添加的这条数据ID,可以通过对象来访问到instance.getSrId()Integer roleId = sysRoleService.addRole(instance);System.out.println("roleId==="+roleId+" instance.srID "+instance.getSrId());根据前面返回的数据ID,来做下面中间表数据的插入多对多数据的添加INSERT INTO sys_role_function(SELECT sr.sr_id,sf.sf_id,sf.sf_typeFROM sys_role sr,sys_function sfWHERE sr.sr_id =2 AND sf.sf_id IN ( 2, 3, 4, 5 ))

你可能感兴趣的:(mybatis实现新添加一条数据,并获取新添加数据的ID)