zoukankan      html  css  js  c++  java
  • springmvc获取所有链接信息

    springmvc获取所有链接信息

    预期结果:
    /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<RequestMappingInfo, HandlerMethod> map = handlerMapping.getHandlerMethods();
            Set<RequestMappingInfo> mappings = map.keySet();
    
    
            for(RequestMappingInfo info : mappings) {
    
            	Set<String> patternSet = new HashSet<String>();
               
            	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配置:

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
    <bean class="com.xxxx.xxxx.AuthorityInitializer" init-method="init" />
  • 相关阅读:
    [转]趣题:一个n位数平均有多少个单调区间?---- From Matrix67
    2015编程之美复赛
    Codeforces Round #304 (Div. 2)
    HDU 5226
    HDU 5225
    HDU 3666
    HDU 4598
    Codeforces Round #303 (Div. 2) E
    编程之美初赛第二场AB
    2015 编程之美初赛第一场 AC题
  • 原文地址:https://www.cnblogs.com/cuiyf/p/7652065.html
Copyright © 2011-2022 走看看