public void init(){
Set<Class<?>> s = ClassUtil.scanPackage("com.x.xx.controller");
s.forEach(item->{
try {
Class aClass = Class.forName(item.getName());
String modelName="";
Api api = (Api) aClass.getAnnotation(Api.class);
if(api!=null){
modelName =AnnotationUtils.getAnnotation(aClass, Api.class).tags()[0];
}
Method[] methods = aClass.getMethods();
for(int i=0;i<methods.length;i++){
Method method = methods[i];
String name="";
String uri="";
String notes="";
ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
if(apiOperation!=null) {
name = AnnotationUtils.getAnnotation(method, ApiOperation.class).value();
notes = AnnotationUtils.getAnnotation(method, ApiOperation.class).notes();
GetMapping getMapping = method.getAnnotation(GetMapping.class);
if(getMapping!=null){
uri = AnnotationUtils.getAnnotation(method, GetMapping.class).value()[0];
}
PostMapping postMapping = method.getAnnotation(PostMapping.class);
if(postMapping!=null){
uri = AnnotationUtils.getAnnotation(method, PostMapping.class).value()[0];
}
RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
if(requestMapping!=null){
uri = AnnotationUtils.getAnnotation(method, RequestMapping.class).value()[0];
}
}
//保存到数据库
if(name!=""){
System.out.println(modelName+"-"+name+"--"+uri);
Permission permission = permissionService.getPermissionByUri(uri);
if(permission ==null){
permission = new Permission();
}
permission.setName(name);
permission.setUri(uri);
permission.setModel(modelName);
permission.setNotes(notes);
permissionService.saveOrUpdateDo(permission);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return;
});
}
05-21
3612
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-13
3317
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)