标签:jsp
上一篇文章:用户权限设计(一)
下面介绍一下权限的更新和验证
@RequestMapping("authDemoSubmit") public String authDemoSubmit(@ModelAttribute("vm") UserAuth mUserAuth) { Map<String, List<String>> authMap = mUserAuth.getUserAuthMap(); Iterator<Map.Entry<String, List<String>>> iterator = authMap.entrySet().iterator(); while(iterator.hasNext( )) { Map.Entry<String, List<String>> entry =iterator.next( ); String objId = entry.getKey( );// 获得对象id String authOperate = list2string(entry.getValue());//获得操作权限 AuthAcc mAuthAcc = testService.getAuthAccByUserIdObjId("004", objId);//根据用户id和对象id获取权限表对象 if(mAuthAcc == null){ // 如果权限为空,则插入一条数据 mAuthAcc = new AuthAcc(); mAuthAcc.setUserId("004");//用户id mAuthAcc.setObjId(objId);//对象id mAuthAcc.setAuthOperate(authOperate);//操作权限 testService.saveAuthAcc(mAuthAcc); }else{ //如果权限不为空,则更新权限 mAuthAcc.setAuthOperate(authOperate);//操作权限 testService.updateAuthAcc(mAuthAcc); } } return "redirect:authDemo.html"; }
private String list2string(List<String> lst){ StringBuffer str = new StringBuffer(); for(String s:lst){ str = str.append(s); } return str.toString(); }
@RequestMapping("authDemoRequest") public String authDemoRequest() { String requestOperate = "u";//假设请求的操作是更新操作,这个参数可以从前台页面传入 //在请求某个对象功能的时候可以如下进行权限验证 AuthAcc mAuthAcc = testService.getAuthAccByUserIdObjId("004", "001");//根据用户id和对象id获取权限表对象 if(mAuthAcc == null){ //没有权限,返回前画面 return "front"; }else{ String authOperate = mAuthAcc.getAuthOperate();//获取用户对应的权限 if(authOperate.contains(requestOperate)){ //如果包含权限,则跳转到下个画面 return "next"; }else{ //没有权限,返回前画面 return "front"; } } }
标签:jsp
原文地址:http://blog.csdn.net/kouwoo/article/details/43405797