新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
预期结果:
/auth/groups/save_menu 保存组的菜单
/auth/menus/add 添加菜单
/auth/menus 获取菜单列表
/auth/menus/delete 删除菜单
public class AuthorityInitializer {
@Autowired
private RequestMappingHandlerMapping handlerMapping;
@Autowired
private AuthService authService;
public void init(){
Map map = handlerMapping.getHandlerMethods();
Set mappings = map.keySet();
for(RequestMappingInfo info : mappings) {
Set patternSet = new HashSet();
PatternsRequestCondition condition = info.getPatternsCondition();
for (String pattern : condition.getPatterns()) {
if(StringUtils.endsWith(pattern, "/")){
patternSet.add(pattern.substring(0, pattern.length()-1));
}else{
patternSet.add(pattern);
}
}
for (String patt : patternSet) {
String value = patt;
String name = info.getName();
if(StringUtils.isBlank(name) ){
name = value;
}
//保存
authService.saveAuthority(value, name);
}
}
}
}
spring配置: