我们接着之前的项目进行开发。
因为要进行角色管理,我们根据数据库结构,添加两个bean类Role和UserRole,属性结构如下:
- Role类

- UserRole类

之后添加RoleDao接口,对bean进行管理
public interface RoleDao {
List<Integer> findRoleIdByUserId(int userId);
List<Role> findRoleByUserId(int id);
void addRole(UserRole userRole);
}
同样,创建新的Mapper,来对应RoleDao
<mapper namespace="com.zhongruan.dao.RoleDao" >
<select id="findRoleIdByUserId" parameterType="int" resultType="int">
select roleId from user_role where userId=#{userId}
</select>
<select id="findRoleByUserId" parameterType="int" resultType="role">
select * from tb_role where id not in (select roleId from user_role where userId=#{id})
</select>
<insert

本文介绍了使用SSM(Spring Security、Spring MVC、MyBatis)框架实现角色权限管理的功能,包括Role和UserRole实体类的创建、RoleDao接口及Mapper的配置、RoleServiceImpl服务实现、Controller中角色管理和批量删除的接口设计,以及一个过滤器类的使用。通过示例展示了批量删除操作的执行和结果验证,以及在角色管理中为用户分配角色的过程,确保数据在数据库中正确更新。
最低0.47元/天 解锁文章
939

被折叠的 条评论
为什么被折叠?



