以角色权限模块中增加功能为例子:
- 概念:
连带操作:首先先在Role表中插入一条数据,接着拿到rid,往Role-Acl表中插入一条数据
-
数据库设计:
Role表:
Role-Acl表:
代码实现:
RoleMap:
/**
* @Description: 新增角色
*/
@Insert("insert into sys_role(rolename,creator,createtime,remark) VALUES(#{rolename},1,NOW(),#{remark})")
@Options(useGeneratedKeys = true, keyProperty = "rid",keyColumn="rid")
int addRole(SysRole sysRole);
RoleAclMap:
/**
* @Description: 插入到角色权限表
*/
@Insert("INSERT into sys_role_acl(rid,aid) VALUES(#{rid},#{aid})")
int addRoleAcl(SysRoleAcl sysRoleAcl);
RoleService:
/**
* @Description: 插入到角色权限表
*/
public Map addRole(SysRole sysRole, String[] aids) {
int addRole = m_RoleMap.addRole(sysRole);
Integer rid = sysRole.getRid();
// SysRoleAcl
SysRoleAcl sysRoleAcl = new SysRoleAcl();
sysRoleAcl.setAid(Arrays.toString(aids));
sysRoleAcl.setRid(rid);
m_RoleAclMap.addRoleAcl(sysRoleAcl);
// 调用IRoleAclMap方法
Map tResultMap = new HashMap();
tResultMap.put("status", "fail");
if (addRole <= 0) {
tResultMap.put("Msg", "添加失败");
return tResultMap;
}
tResultMap.put("status", "success");
return tResultMap;
}