在做crm项目,角色添加权限功能,插入角色数据时,需要获取角色id添加到角色权限中间表,但获取的角色id是空,经查询,解决办法如下
在insert标签中,加入keyProperty和useGeneratedKeys两个属性:
!-- 增加 -->
insert into t_role (
sn, name, tenant_id
)values(
#{sn},
#{name},
#{tenantId}
)
useGeneratedKeys设置为true,keyProperty设置为出入对象的主键属性。
这样,在执行了方法后,然后roles.getId()救你拿到插入数据后的id。
原文:https://blog.csdn.net/Snower08/article/details/82975809