自增ID问题
插入
@Override
@Transactional(rollbackFor = Exception.class)
public Long add(GovDingUserDO entity) {
entity.setId(snowBeanConfig.getIdWorker().nextId());
govDingUserMapper.insertSelective(entity);
return entity.getId();
}
采用的雪花ID作为主键,成功返回ID,即雪花ID
mapper
<insert id="insertSelective" parameterType="com.jandar.sso.pojo.GovDingUserDO" >
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
select LAST_INSERT_ID()
</selectKey>
insert into t_gov_ding_user
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
......
问题:插入成功返回的不是雪花ID,而是表自增主键的值
原因:
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
select LAST_INSERT_ID()
</selectKey>
扩展: return entity.getId();获取到的id到底是取的哪个?原理是什么?
标签:INSERT,自增,雪花,ID,问题,entity,主键,select From: https://blog.51cto.com/u_16082754/7057482