【问题标题】:@RequestParam value converted to lower case@RequestParam 值转换为小写
【发布时间】:2016-03-24 14:40:33
【问题描述】:

我有一个简单的控制器,其中包含如下请求参数:

@RequestParam(required = false) String name

现在我也有 mockmvc 测试包含:

mockMvc.perform(get("/rest/hello/greet")
    .param("name", "Marcel"))

在日志记录中,我看到请求参数似乎正确传递:

MockHttpServletRequest:
  HTTP Method = GET
  Request URI = /rest/hello/greet
   Parameters = {name=[Marcel]}

但是在我的控制器中,请求参数以小写形式出现..

@Get(path = "/greet", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<JSONObject> greet(@RequestParam(required = false) String name) {
    logger.info("greet called with name: {}", name);

它打印greet called with name: marcel。 此外 - 显然 - 当将此参数传递给其他服务时,它以小写形式传递。

这是一个非常简单的 Spring Boot 应用程序,所以我想知道为什么这个请求参数是小写的。

【问题讨论】:

  • 检查 servlet 过滤器或控制器方法周围的一些 AOP。

标签: spring spring-mvc spring-boot spring-test-mvc


【解决方案1】:

发现一些 Converter&lt;String, String&gt; 存在于导致此问题的应用程序上下文中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 2011-07-21
    • 2014-04-26
    • 2022-01-24
    • 2018-11-21
    • 1970-01-01
    • 2021-10-13
    相关资源
    最近更新 更多