时间:2021-07-01 10:21:17 帮助过:6人阅读
@RequestMapping(value="/insertSelective",method={RequestMethod.GET,RequestMethod.POST}) @ResponseBody public Object insertSelective(Auth_role record,HttpSession session){ Userinfo sessionUserinfo = (Userinfo)session.getAttribute("CURR_USER"); String sessionuserid = sessionUserinfo.getUserid().toString(); record.setAdduser(Integer.parseInt(sessionuserid));
Map map = new HashMap(); int result = 0; /*异常处理*/ try { result = service.insertSelective(record); }catch (org.springframework.dao.DuplicateKeyException e){ /*异常处理截获流程,如果是存在DuplicateKeyException则是重名,直接返回到前端,id主键为自增长,不会重复*/ map.put("code", "fail"); map.put("msg", "该角色名已存在!"); return map; } /*正常返回流程*/ if (result == 1) { map.put("code", "success"); map.put("msg", CN_MessageEnum.AddSuccess.getName()); }else { map.put("code", "fail"); map.put("msg", CN_MessageEnum.AddFailed.getName()); } return map; }
数据库唯一性约束异常插入处理
标签:col char sage ppi pre def dfa com 重复