如何区分授权角色在左侧,未授权在右侧
来源:互联网 发布:java post accept 编辑:程序博客网 时间:2024/04/28 15:14
如何实现以下效果
代码如下:
/** * 辅助查询 * @param list * @return */public Map<String,String> changMapByUserRole(List<SysUserRoleR> list){ Map<String,String> resultMap = new HashMap<>(); for(SysUserRoleR roleR:list){
//设置一个标志 resultMap.put(roleR.getRoleId(),"1"); } return resultMap;}思路:把所有的角色查询出来,然后利用map的属性来进行区分。
解释:
形参:将关联表中的所有角色查询出来。
以下代码是主查询的实现
/** * 主要代码 * @param req 接受的是json串,传json传的http请求只能是POST * @return */@RequestMapping(value = "/findAllRole",method = RequestMethod.POST)@ResponseBodypublic Object findAllRole(@RequestBody String req){ SysUserRoleR sur = null; try{
//这里将json传转换为对象,只有key与对象的属性一致才能转换成功,否则失败 sur = jsonTranster.readValue(req,SysUserRoleR.class); }catch (Exception e){ e.printStackTrace(); return addResultMapMsg(false,e.getMessage()); }
//判断对象是否为空或者用户的主键未传 if(BeanUtils.isBlank(sur) || StringUtils.isEmpty(sur.getUserId())){ return addResultMapMsg(false,"未传入userId"); } //查询出所有角色 List<Role> rolelist = roleService.findAll(); if(rolelist.size() == 0 || rolelist.isEmpty()){ return addResultMapMsg(false,"用户角色列表查询失败"); } //根据用户id查询角色 List<SysUserRoleR> list = sysUserRoleRService.findByUserId(sur.getUserId()); if(list == null){ return addResultMapMsg(true,rolelist); }
//调用上面的辅助查询方法 Map<String,String> roleMap = changMapByUserRole(list);
//遍历所有的角色 for(Role role:rolelist){
//利用辅助查询里面的设置来判断角色是否授权,如果有id就和“1”进行来进行判断 if("1".equals(roleMap.get(role.getId()))){ //当前用户有的角色
//判断有这个id设置Role中的标示字段为true,否则为false,前端会根据这个字段的属性进行区分 role.setRoleFlag(true); }else{ role.setRoleFlag(false); } } return addResultMapMsg(true,rolelist);}
阅读全文
0 0
- 如何区分授权角色在左侧,未授权在右侧
- 角色授权
- 在SQL Server中创建用户角色及授权
- 在SQL Server中创建用户角色及授权
- Shiro在web的授权检测(权限角色验证)
- 在SQL Server中创建用户角色及授权
- 在SQL Server中创建用户角色及授权
- 在SQL Server中创建用户角色及授权
- ORA-01932 选项未授权给角色'CONNECT'
- ORA-01932: ADMIN 选项未授权给角色 'CONNECT'
- 在Android实现客户端授权
- 角色,创建,授权
- MVC4角色授权
- 在SQL Server中创建用户角色及授权(使用SQL语句)
- 在SQL Server中创建用户角色及授权(使用SQL语句)
- poj 2318 TOYS--点在直线左侧还是右侧
- 点击左侧菜单在右侧弹出相应的内容
- Word2013正面页码显示在右侧,反面页码左侧显
- 资讯丨NVIDIA自造AI超级计算机:轻松进入世界前五
- maven 添加自己的包到本地仓库及到项目中
- 免费教材丨第51期:数学基础课程----概率论教程、机器学习中的数学基础
- Linux UDEV规则写串口别名
- 简单猜数字游戏
- 如何区分授权角色在左侧,未授权在右侧
- IDEA:Error:java: Compilation failed: internal java compiler error
- Word2013查找替换功能之:批量去掉所有英文字符
- Ubuntu14安装gcc4.4.7
- 你知道应聘上一份机器学习的工作需要哪些条件吗?
- 纹理特征
- leetcode 69. Sqrt(x) 367. Valid Perfect Square
- 国内丨人工智能(AI)引发的中国经济新动能
- map与unordered_map的基本操作