网站登录页做多大尺寸的,做直播网站要多大带宽,怎么免费制作一个网站,友情链接买卖平台今天在做项目的时候需要用到上次数据更新或者插入的id#xff0c;学习了一下找到此方法#xff0c;记录一下。 在MyBatis中#xff0c;当插入一条新数据后#xff0c;可以使用useGeneratedKeys属性和keyProperty属性来获取新插入数据的ID。useGeneratedKeys属性告诉MyBatis… 今天在做项目的时候需要用到上次数据更新或者插入的id学习了一下找到此方法记录一下。 在MyBatis中当插入一条新数据后可以使用useGeneratedKeys属性和keyProperty属性来获取新插入数据的ID。useGeneratedKeys属性告诉MyBatis使用JDBC的getGeneratedKeys方法来获取数据库生成的主键keyProperty属性则指定哪个Java对象的属性应该被设置为这个主键。
在xml中在做更新操作时加入useGeneratedKeys属性和keyProperty属性或者上次更新数据的id。 update idupdateStationManagerInfo useGeneratedKeystrue keyPropertyidupdate storage_tool_station_info_confirmset team_manager_id #{teamManagerId},team_manager_face #{teamManagerFace},team_manager_confirm_time SYSDATE(),station_account_id #{stationAccountId},station_face #{stationFace},station_confirm_time SYSDATE(),type #{type}where id #{id}/update
在xml中在做插入操作时加入useGeneratedKeys属性和keyProperty属性 获取上次插入数据的id insert idinsertStationManagerInfo useGeneratedKeystrue keyPropertyidINSERT INTO storage_tool_station_info_confirm(model_id, team_id, team_manager_id, team_manager_face,team_manager_confirm_time, station_account_id, station_face,station_confirm_time,tool_count, operate_time, receiptor, type)VALUES (#{modelId}, #{teamId}, #{teamManagerId}, #{teamManagerFace}, #{teamManagerConfirmTime},#{stationAccountId}, #{stationFace}, #{stationConfirmTime}, #{recipentCount}, #{operateTime},#{receiptor}, #{type});/insert java代码里取出就可以了
例如
//更新操作
warehouseRequisitionMapper.updateStationManagerInfo(toolInfoConfirm);
//取id
log.info(id-------------:toolInfoConfirm.getId());插入数据
//取id
log.info(Insert StorageToolInfoConfirm successfully.);
log.info(id-------------:toolInfoConfirm.getId());
注意在使用此方式取id时需要保证数据库表的id是自增的。