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() +"\n" + entry.getValue());
        }
    }
}

你可能感兴趣的:(SpringMVC项目中获取所有URL到Controller Method的映射)