if(false) return R.error(511,"永不会进入"); else if("用户".equals(role)) params.put("yonghuId",request.getSession().getAttribute("userId")); else if("医生".equals(role)) params.put("yishengId",request.getSession().getAttribute("userId")); if(params.get("orderBy")==null || params.get("orderBy")==""){ params.put("orderBy","id"); }
时间: 2023-07-13 21:03:56 浏览: 44
这段代码是一个Java中的条件语句,根据不同的情况设置不同的参数。
首先判断条件为false,因此代码不会执行第一行中的语句,并且不会返回错误码511。
接下来,根据角色的不同,将不同的参数添加到params中。如果角色为"用户",则将session中的"userId"作为"yonghuId"添加到params中;如果角色为"医生",则将session中的"userId"作为"yishengId"添加到params中。
最后,如果params中没有"orderBy"参数或者"orderBy"参数值为null或者空字符串,则将"orderBy"参数设置为"id"。
相关问题
@RequestMapping("/page") public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){ logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); String role = String.valueOf(request.getSession().getAttribute("role")); if(false) return R.error(511,"永不会进入"); else if("老师".equals(role)){ params.put("laoshiId",request.getSession().getAttribute("userId")); LaoshiEntity laoshiEntity = laoshiService.selectById(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); if(laoshiEntity == null) return R.error("查不到登录的老师"); params.put("yuanxiTypes", laoshiEntity.getYuanxiTypes()); } if(params.get("orderBy")==null || params.get("orderBy")==""){ params.put("orderBy","id"); } PageUtils page = banjiService.queryPage(params); //字典表数据转换 List<BanjiView> list =(List<BanjiView>)page.getList(); for(BanjiView c:list){ //修改对应字典表字段 dictionaryService.dictionaryConvert(c, request); } return R.ok().put("data", page); }把这段代码改为不需要验证身份
可以将以下代码删除或注释掉,即可实现不需要验证身份:
```
String role = String.valueOf(request.getSession().getAttribute("role"));
if(false)
return R.error(511,"永不会进入");
else if("老师".equals(role)){
params.put("laoshiId",request.getSession().getAttribute("userId"));
LaoshiEntity laoshiEntity = laoshiService.selectById(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
if(laoshiEntity == null)
return R.error("查不到登录的老师");
params.put("yuanxiTypes", laoshiEntity.getYuanxiTypes());
}
```
@RequestMapping("/page") public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){ logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); String role = String.valueOf(request.getSession().getAttribute("role")); if(false) return R.error(511,"永不会进入"); else if("用户".equals(role)) params.put("yonghuId",request.getSession().getAttribute("userId")); else if("医生".equals(role)) params.put("yishengId",request.getSession().getAttribute("userId")); if(params.get("orderBy")==null || params.get("orderBy")==""){ params.put("orderBy","id"); } PageUtils page = guahaoService.queryPage(params); //字典表数据转换 List<GuahaoView> list =(List<GuahaoView>)page.getList(); for(GuahaoView c:list){ //修改对应字典表字段 dictionaryService.dictionaryConvert(c, request); } return R.ok().put("data", page); }请详细解释一下
这是一个使用 Spring MVC 框架编写的 Controller 的方法,通过 @RequestMapping 注解将该方法映射到 "/page" 路径,当请求到达该路径时,会执行该方法。
该方法接受两个参数:params 和 request,其中 params 是一个 Map,用于存储请求中的参数,request 是 HttpServletRequest 对象,用于获取请求相关的信息。
该方法首先打印日志,记录下当前 Controller 类的名称和传入的参数。然后获取当前用户的角色,如果角色为 "用户",则将该用户的 ID 存入 params 中的 "yonghuId" 中,如果角色为 "医生",则将该用户的 ID 存入 params 中的 "yishengId" 中。
接下来,如果请求中没有指定 "orderBy" 参数,则将其设置为 "id"。然后调用 guahaoService 的 queryPage 方法查询数据,并将其封装为一个 PageUtils 对象。
最后,将查询结果中的字典表数据进行转换,使用 dictionaryService 的 dictionaryConvert 方法将字典表中的代码值转换为对应的中文值。最后返回一个包含查询结果的 R 对象。