fixed regression: method-level patterns without type-level pattern do not need to start with a slash (SPR-6598)

This commit is contained in:
Juergen Hoeller
2010-02-17 23:26:06 +00:00
parent b54a099f49
commit e74b33242b
3 changed files with 64 additions and 8 deletions

View File

@@ -487,8 +487,11 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
boolean match = false;
if (mappingInfo.paths.length > 0) {
List<String> matchedPaths = new ArrayList<String>(mappingInfo.paths.length);
for (String methodLevelPattern : mappingInfo.paths) {
String matchedPattern = getMatchedPattern(methodLevelPattern, lookupPath, request);
for (String mappedPattern : mappingInfo.paths) {
if (!hasTypeLevelMapping() && !mappedPattern.startsWith("/")) {
mappedPattern = "/" + mappedPattern;
}
String matchedPattern = getMatchedPattern(mappedPattern, lookupPath, request);
if (matchedPattern != null) {
if (mappingInfo.matches(request)) {
match = true;

View File

@@ -154,11 +154,11 @@ public class DefaultAnnotationHandlerMapping extends AbstractDetectingUrlHandler
/**
* Derive URL mappings from the handler's method-level mappings.
* @param handlerType the handler type to introspect
* @param indicateEmpty whether the returned array should contain
* <code>null</code> in case of an empty {@link RequestMapping} value.
* @param hasTypeLevelMapping whether the method-level mappings are nested
* within a type-level mapping
* @return the array of mapped URLs
*/
protected String[] determineUrlsForHandlerMethods(Class<?> handlerType, final boolean indicateEmpty) {
protected String[] determineUrlsForHandlerMethods(Class<?> handlerType, final boolean hasTypeLevelMapping) {
String[] subclassResult = determineUrlsForHandlerMethods(handlerType);
if (subclassResult != null) {
return subclassResult;
@@ -175,10 +175,13 @@ public class DefaultAnnotationHandlerMapping extends AbstractDetectingUrlHandler
String[] mappedPatterns = mapping.value();
if (mappedPatterns.length > 0) {
for (String mappedPattern : mappedPatterns) {
if (!hasTypeLevelMapping && !mappedPattern.startsWith("/")) {
mappedPattern = "/" + mappedPattern;
}
addUrlsForPath(urls, mappedPattern);
}
}
else if (indicateEmpty) {
else if (hasTypeLevelMapping) {
// empty method-level RequestMapping
urls.add(null);
}