• SpringMVC项目中获取所有URL到Controller Method的映射


    package com.wsn.controller;
    
    import com.wsn.entity.AuthUser;
    import com.wsn.exception.BusinessException;
    import com.wsn.service.UserService;
    import org.apache.log4j.Logger;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.http.HttpRequest;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.util.StringUtils;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    
    
    /**
     * 用户Controller
     */
    @Controller
    @RequestMapping("/sandbox")
    public class SandboxController {
    
        private static final Logger LOGGER = Logger.getLogger(SandboxController.class);
        @Autowired
        private RequestMappingHandlerMapping handlerMapping;
    
        @RequestMapping("/index")
        public void index(Long id, HttpServletRequest request, HttpServletResponse response) throws IOException, ClassNotFoundException {
    
            Map map =  this.handlerMapping.getHandlerMethods();
            Iterator<?> iterator = map.entrySet().iterator();
            while(iterator.hasNext()){
                Map.Entry entry = (Map.Entry) iterator.next();
                System.out.println(entry.getKey() +"
    " + entry.getValue());
            }
        }
    }
  • 相关阅读:
    toj 2819 Travel
    toj 2807 Number Sort
    zoj 2818 Prairie dogs IV
    zoj 1276 Optimal Array Multiplication Sequence
    toj 2802 Tom's Game
    toj 2798 Farey Sequence
    toj 2815 Searching Problem
    toj 2806 Replace Words
    toj 2794 Bus
    css截取字符
  • 原文地址:https://www.cnblogs.com/root429/p/9251360.html
Copyright © 2020-2023  润新知