tkMyBatis执行insert返回主键

数据库:MySQL

组件:tkMyBatis,和MyBatis有些不同

 

ActiveTaskLog taskLogDto = new ActiveTaskLog();
taskLogDto.setMemberId(oldMemberId);
long taskLogId = iActiveventLogDao.insertTaskLog(taskLogDto);
Map oldMemberInfo = new HashMap<>();

oldMemberInfo.put("id", taskLogDto.getId());

ActiveTaskLog 的主键为id :private Long id;


    INSERT INTO active_task_log (
    `member_id`
    )
    VALUES
    (#{memberId})

mapper的insert语句添加useGeneratedKeys="true" keyProperty="id",注意,在tkMyBatis中,iActiveventLogDao.insertTaskLog(taskLogDto)返回的是0或1,如果你想使用返回的id,必须使用ActiveTaskLog对象获取:  oldMemberInfo.put("id", taskLogDto.getId());

 

 

你可能感兴趣的:(MyBatis使用指南)