Spring Regular Expression URI Templates

Hey, someone knows how to combine this URI "http: // localhost: 8080 / test / user / 127.0.0.1: 8002: 8" with @RequestMapping.

I am trying to write this code:

@RequestMapping(value = "/user/{id}", method = RequestMethod.GET,headers="Accept=application/xml" )
public void test(@PathVariable("id") String id) {
System.out.println(id);
return null;
}

but the problem is that when I print the identifier, this value is: 127.0.0 Maybe something happened?

+5
source share
2 answers

See Spel documentation: http://static.springsource.org/spring/docs/3.0.5.RELEASE/reference/expressions.html

You need to do something like this:

@RequestMapping(value = "/user/{id:.*}", method = RequestMethod.GET,headers="Accept=application/xml" )
public void test(@PathVariable("id") String id) {
+11
source

If you use style @Configurationwith Spring MVC, this will do the trick:

@Configuration
public class Api extends WebMvcConfigurationSupport {

    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
        mapping.setUseSuffixPatternMatch(false);
        return mapping;
    }

}

As you can see, you should disable useSuffixPatternMatchat RequestMappingHandlerMapping.

See also:

+4

All Articles