Spring MVC Missing matrix variable

前端 未结 2 1566
萌比男神i
萌比男神i 2021-01-07 06:32

I\'m trying to add a matrix parameter (or matrix variable) to my Rest Controller using SpringMVC (from Spring boot 1.2.3.RELEASE) Here is my code :

@RestCont         


        
相关标签:
2条回答
  • 2021-01-07 07:01

    In SpringBoot Application In order to enable Matrix variables you need to define below override code

    @Configuration
    public class WebConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            UrlPathHelper urlPathHelper = new UrlPathHelper();
            urlPathHelper.setRemoveSemicolonContent(false);
            configurer.setUrlPathHelper(urlPathHelper);
        }
    }
    

    Otherwise, they’re disabled by default

    0 讨论(0)
  • 2021-01-07 07:21

    As the documentation you linked to states,

    Note that to enable the use of matrix variables, you must set the removeSemicolonContent property of RequestMappingHandlerMapping to false. By default it is set to true with the exception of the MVC namespace and the MVC Java config both of which automatically enable the use of matrix variables.

    If you're configuring your application by extending WebMvcConfigurationSupport, then override the requestMappingHandlerMapping method which prepares the RequestMappingHandlerMapping and set its appropriate property.

    @Override
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        final RequestMappingHandlerMapping requestMappingHandlerMapping = super.requestMappingHandlerMapping();
        requestMappingHandlerMapping.setRemoveSemicolonContent(false); // <<< this
        return requestMappingHandlerMapping;
    }
    

    You'll then be all set.


    With Spring Boot, I think all you need is to declare a @Bean method with the above, ie. that returns a RequestMappingHandlerMapping instance.

    0 讨论(0)
提交回复
热议问题