1、把一个list里面的数据转换成另外一个list
Map<String, HandlerMapping> matchingBeans =
BeanFactoryUtils.beansOfTypeIncludingAncestors(contextRefreshedEvent.getApplicationContext(), HandlerMapping.class, true, false);
ArrayList<HandlerMapping> list = new ArrayList<>(matchingBeans.values());
AnnotationAwareOrderComparator.sort(list);
ArrayList<String> ss = new ArrayList();
list.forEach(k -> ss.add(k.getClass().getName()));
log.info("HandlerMappingList = {}", JSON.toJSONString(ss));
输出的结果为:
[
"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping",
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping",
"org.springframework.web.socket.server.support.WebSocketHandlerMapping",
"org.springframework.web.socket.server.support.WebSocketHandlerMapping",
"org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping",
"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping",
"org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping"
]
2、一个map转换为另外一个map
Map<String, HandlerMapping> matchingBeans =
BeanFactoryUtils.beansOfTypeIncludingAncestors(contextRefreshedEvent.getApplicationContext(), HandlerMapping.class, true, false);
Map<String, String> result = new HashMap<>();
matchingBeans.forEach((k, v) -> {
result.put(k, v.getClass().getName());
});
log.info("HandlerMapping = {}", JSON.toJSONString(result));
输出的结果为:
{
"stompWebSocketHandlerMapping": "org.springframework.web.socket.server.support.WebSocketHandlerMapping",
"welcomePageHandlerMapping": "org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping",
"faviconHandlerMapping": "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping",
"beanNameHandlerMapping": "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping",
"resourceHandlerMapping": "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping",
"webSocketHandlerMapping": "org.springframework.web.socket.server.support.WebSocketHandlerMapping",
"requestMappingHandlerMapping": "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"
}
|