我试图使我的 URL 不区分大小写,并从网上获取以下代码。
但是,现在当我的网址有数字时,它会给我状态 400 错误。在此更改之前它工作正常。现在无法识别 localhost\toplevel\234\text\2342 之类的 URL。有人可以帮助解释为什么会发生这种情况以及需要进行哪些更改才能使这些网址正常工作。
public class CaseInsensitiveAnnotationHandlerMapping extends AntPathMatcher
protected boolean doMatch(String pattern,
String path, boolean fullMatch, Map<String, String> uriTemplateVariables) {
return super.doMatch(pattern.toLowerCase(),
path.toLowerCase(), fullMatch, uriTemplateVariables);
}
}
我的 Servlet-Context.xml
<beans:bean class="com.darproject.webUtils.CaseInsensitiveAnnotationHandlerMapping" />
<beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<beans:bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
<beans:bean name="handlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<beans:property name="webBindingInitializer">
<beans:bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<beans:property name="conversionService" ref="conversion-service"></beans:property>
<beans:property name="validator">
<beans:bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<beans:property name="providerClass" value="org.hibernate.validator.HibernateValidator"></beans:property>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
<beans:property name="messageConverters">
<beans:list>
<beans:ref bean="byteArrayConverter"/>
<beans:ref bean="jaxbConverter"/>
<beans:ref bean="jsonConverter"/>
<beans:bean class="org.springframework.http.converter.StringHttpMessageConverter"></beans:bean>
<beans:bean class="org.springframework.http.converter.ResourceHttpMessageConverter"></beans:bean>
<beans:bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"></beans:bean>
<beans:bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"></beans:bean>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean name="byteArrayConverter" class="org.springframework.http.converter.ByteArrayHttpMessageConverter"></beans:bean>
<beans:bean name="jaxbConverter" class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"></beans:bean>
<beans:bean name="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></beans:bean>
<beans:bean name="caseInsensitivePathMatcher" class="com.darproject.webUtils.CaseInsensitiveAnnotationHandlerMapping"/>
<beans:bean name="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<beans:property name="pathMatcher" ref="caseInsensitivePathMatcher"></beans:property>
</beans:bean>
现在不起作用的方法。
@RequestMapping(value="/commentswindow/{defectId}/{release}/{defectsRowID}",method=RequestMethod.POST)
public String addUserComments(
@PathVariable("defectsRowID") long defectsRowID,
@PathVariable("defectId") String defectId,
@PathVariable("release") String release,
@ModelAttribute("addComments") UserCommentsModel cmtModel,
BindingResult results,
Model model,
HttpServletRequest request,
HttpServletResponse response){