How can I have case insensitive URLS in Spring MVC with annotated mappings

前端 未结 6 1826
感情败类
感情败类 2020-11-29 22:39

I have annotated mappings working great through my spring mvc web app, however, they are case sensitive. I cannot find a way to make them case insensitive. (I\'d love to mak

6条回答
  •  盖世英雄少女心
    2020-11-29 23:02

    According to this webpost you need to add both a HandlerMapping and a HandlerAdapter in Spring MVC. The Mapping maps the request to a corresponding controller, and the adapter is responsible to execute the request using the controller.

    You therefore need to override the PathMatcher for both the mapper and adapter.

    Ex (will make all @Controllers case-insensitive):

    New Matcher:

    public class CaseInsenseticePathMatcher extends AntPathMatcher {
        @Override
        protected boolean doMatch(String pattern, String path, boolean fullMatch, Map uriTemplateVariables) {
            System.err.println(pattern + " -- " + path);
            return super.doMatch(pattern.toLowerCase(), path.toLowerCase(), fullMatch, uriTemplateVariables);
        }
    }
    

    applicationContext.xml:

    
    
    
        
    
    
    
        
        
            
        
        
            
                
                
                
                
            
        
    
    
    
    

    Added about the same that would do. (Thanks to David Parks for the link)

提交回复
热议问题