spring BeanNameUrlHandlerMapping 源码
spring BeanNameUrlHandlerMapping 代码
文件路径:/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.servlet.handler;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.StringUtils;
/**
* Implementation of the {@link org.springframework.web.servlet.HandlerMapping}
* interface that maps from URLs to beans with names that start with a slash ("/"),
* similar to how Struts maps URLs to action names.
*
* <p>This is the default implementation used by the
* {@link org.springframework.web.servlet.DispatcherServlet}, along with
* {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping}.
* Alternatively, {@link SimpleUrlHandlerMapping} allows for customizing a
* handler mapping declaratively.
*
* <p>The mapping is from URL to bean name. Thus an incoming URL "/foo" would map
* to a handler named "/foo", or to "/foo /foo2" in case of multiple mappings to
* a single handler.
*
* <p>Supports direct matches (given "/test" -> registered "/test") and "*"
* matches (given "/test" -> registered "/t*"). For details on the pattern
* options, see the {@link org.springframework.web.util.pattern.PathPattern}
* javadoc.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @see SimpleUrlHandlerMapping
*/
public class BeanNameUrlHandlerMapping extends AbstractDetectingUrlHandlerMapping {
/**
* Checks name and aliases of the given bean for URLs, starting with "/".
*/
@Override
protected String[] determineUrlsForHandler(String beanName) {
List<String> urls = new ArrayList<>();
if (beanName.startsWith("/")) {
urls.add(beanName);
}
String[] aliases = obtainApplicationContext().getAliases(beanName);
for (String alias : aliases) {
if (alias.startsWith("/")) {
urls.add(alias);
}
}
return StringUtils.toStringArray(urls);
}
}
相关信息
相关文章
spring AbstractDetectingUrlHandlerMapping 源码
spring AbstractHandlerExceptionResolver 源码
spring AbstractHandlerMapping 源码
spring AbstractHandlerMethodExceptionResolver 源码
spring AbstractHandlerMethodMapping 源码
spring AbstractUrlHandlerMapping 源码
spring ConversionServiceExposingInterceptor 源码
spring DispatcherServletWebRequest 源码
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦