【问题标题】:Sending % through @RequestParam in Spring在 Spring 中通过 @RequestParam 发送 %
【发布时间】:2021-02-05 10:41:15
【问题描述】:

如何在 Spring 中使用@RequestParam 发送%

我通过这个 URL 调用 API:http://localhost:8080/springmvc/test?param1=%

但我无法在 API 中获得 %。当我调试时,我得到了param1 = null,但我想得到真正的角色%。如何获得?

这是我的 API:

public List<Test> testParam(
            @PathVariable("test") string test,
            @RequestParam(value = "param1", required = false) string myParaml) {
  ...
}

【问题讨论】:

    标签: java spring spring-mvc http-request-parameters


    【解决方案1】:

    使用特殊符号的 URL 编码作为参数

    %   =  %25
    

    Reference

    如果想用Java阅读,你需要解码 Ref 2

    【讨论】:

      【解决方案2】:

      您必须在 URL 中以 UTF-8 编码标准发送特殊字符。

      尝试将% 发送为%25,这是UTF-8 编码等效的。

      http://localhost:8080/springmvc/test?param1=%25
      

      这会奏效。更多信息请参考here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-14
        • 1970-01-01
        • 2017-09-20
        • 1970-01-01
        相关资源
        最近更新 更多