要求,使用redis缓存,根据用户角色可以动态展示菜单
1, mapper层
接口
public interface MenuMapper {
//根据角色id查询一级菜单
List<Menu> selectFirstLevelMenus(Integer roleId);
//根据一级菜单Id查询二级菜单
List<Menu> selectSecondLevelMenus(Integer id);
}
xml映射文件
<select id="selectFirstLevelMenus" resultType="Menu">
select id, m.name, path, icon
from t_menu m,
t_role_menu rm
where m.id = rm.menu_id
and rm.role_id = #{
roleid}
and level = 1
ORDER BY priority
</select>
<select id="selectSecondLevelMenus" resultType="Menu">
select name,linkurl ,path from t_menu where parentMenuId=#{
id}
</select>
2 ,实现登录的userserImpl中存权限或者角色之前,根据角色id得到一级菜单继而得到二级菜单,并且存入redisd的List中
@Service
@Transactional
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private RoleMapper roleMapper;
@Autowired