重新加载

 1    @RequestMapping("/reload")
 2     @ResponseBody
 3     public JsonResult reload(){
 4         JsonResult js = new JsonResult();
 5         try {
 6             //获取数据库中的所有权限
 7             List<String> permissionList = permissionService.selectExpression();
 8             //从上下文获取所有的controller
 9             Map<String, Object> beans = context.getBeansWithAnnotation(Controller.class);
10             for (Object value : beans.values()) {
11                 //判断是不是cglib动态代理
12                 if (!AopUtils.isCglibProxy(value)){
13                     continue;
14                 }
15                 //当是cglib的动态代理的时候,获取controller的字节码
16                 Class clazz= value.getClass().getSuperclass();
17                 //获取所有的method
18                 Method[] methods = clazz.getDeclaredMethods();
19                 //遍历
20                 for (Method method : methods) {
21                     //获取method上的权限注解
22                     RequiresPermissions annotation = method.getAnnotation(RequiresPermissions.class);
23                     if (annotation != null){
24                         //获取值
25                         String expression = annotation.value()[0];
26                         String name = annotation.value()[1];
27 
28                         if (!permissionList.contains(expression)){
29                             System.out.println(expression);
30                             System.out.println(name);
31 
32                             Permission permission = new Permission();
33                             permission.setExpression(expression);
34                             permission.setName(name);
35                             permissionService.insert(permission);
36                         }
37                     }
38                 }
39 
40             }
41             js.setMsg("操作成功");
42             js.setFlag(true);
43             return js;
44         } catch (Exception e) {
45             e.printStackTrace();
46             js.setFlag(false);
47             js.setMsg("操作失败");
48             return js;
49         }
50     }

 

posted @ 2020-12-06 18:06  y海涛  阅读(746)  评论(0编辑  收藏  举报