@PathVariable不接受Spring Boot中的尾部空格

时间:2016-07-14 11:15:43

标签: java spring spring-boot

我们正在使用Spring Boot构建rest api,我在Spring Boot rest api中遇到@PathVariable问题。它不接受URL中路径参数中的试验空白。

此网址有效:

https://foo.com/api/v1/pen/?param1=foobar

但是在url下面不起作用,它会删除尾随空格:

https://foo.com/api/v1/pen /?param1=foobarfoo

是的,它可能看起来很奇怪,但我们有要求,因为这个api进行了大量的数据库搜索,甚至没有空格的空格也会影响输出。 这就是我的请求映射的样子:

@RequestMapping(value="api/v1/{sentenceToSearch}",method=RequestMethod.GET,produces={MediaType.APPLICATION_JSON})

我在stackoverflow中搜索了很多问题,如:

Controller Pathvariable bind removes ending space

但上述问题并没有解决方案。还尝试了各种有问题的问题,以防止修剪"。"来自网址,并根据我尝试添加以下代码:

@Configuration
  protected static class AllResources extends WebMvcConfigurerAdapter {

      @Override
      public void configurePathMatch(PathMatchConfigurer matcher) {
          matcher.setUseRegisteredSuffixPatternMatch(true);
      }

  }

但它适用于"。"不是为了特殊字符,我也尝试在请求映射中添加这样的表达式:{sentenceToSearch:.+}但是所有这些都不起作用。

有人可以帮助我吗?

0 个答案:

没有答案