简体   繁体   English

通过 Spring 中的 @RequestParam 发送 %

[英]Sending % through @RequestParam in Spring

How to send % using @RequestParam in Spring?如何在 Spring 中使用@RequestParam发送%

I'm calling the API by this URL: http://localhost:8080/springmvc/test?param1=%我通过这个 URL 调用 API: http://localhost:8080/springmvc/test?param1=%

But I'm not able to get the % in the API.但我无法获得 API 中的 %。 When I'm debugging, I'm getting param1 = null but I want to get the real character % .当我调试时,我得到param1 = null但我想得到真正的字符% How to get that?如何得到它?

This is my API:这是我的 API:

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

Use URL encoding for special symbols as parameters对特殊符号使用 URL 编码作为参数

%   =  %25

Reference参考

You need to decode if want to read in Java Ref 2如果要读取 Java Ref 2 ,您需要解码

You have to send special characters in UTF-8 encoded standard in the URL.您必须在 URL 中发送 UTF-8 编码标准中的特殊字符。

Try to send % as %25 , which is UTF-8 encoded equivalent.尝试将%作为%25发送,这是UTF-8 编码的等效项。

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

This will work.这将起作用。 Refer here for more.请参阅此处了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM