spring MVC
DispatcherServlet #doDispatch
-> HandlerExecutionChain
-> HandlerAdapter
-> HandlerExecutionChain.pre
-> HandlerAdapter.handle
-> HandlerExecutionChain.post
九大内置对象
HandlerMapping
HandlerAdapter
HandlerExceptionResolver
RequestToViewNamelator
ViewResolver
LocaleResolver
ThemeResolver
MultipartResolver
FlashMapManager
获取系统的所有url映射mapping方法
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.util.*;
@RestController
@RequestMapping("/test")
@Slf4j
public class MappingController {
@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;
@RequestMapping(value = "/mappings")
public String list(Model model) {
List<HashMap<String, String>> urlList = new ArrayList<HashMap<String, String>>();
List<String> list = new ArrayList<>();
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
for (Map.Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {
HashMap<String, String> hashMap = new HashMap<String, String>();
RequestMappingInfo info = m.getKey();
HandlerMethod method = m.getValue();
PatternsRequestCondition p = info.getPatternsCondition();
for (String url : p.getPatterns()) {
hashMap.put("url", url);
list.add(url);
}
hashMap.put("className", method.getMethod().getDeclaringClass().getName());
hashMap.put("method", method.getMethod().getName());
RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
String type = methodsCondition.toString();
if (type != null && type.startsWith("[") && type.endsWith("]")) {
type = type.substring(1, type.length() - 1);
hashMap.put("type", type);
}
urlList.add(hashMap);
}
model.addAttribute("list", urlList);
list.forEach(a-> System.out.println(a));
for (HashMap<String, String> hashMap : urlList) {
hashMap.entrySet().stream().forEach(a->{
System.out.println(a.getValue());
});
System.out.println();
}
return "/console/system/mappingList";
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)