java - Spring请求参数中的特殊符号

标签 java spring

我有

@RequestMapping(value ="/getTaxiByPhone",method = RequestMethod.GET)
public @ResponseBody
String getTaxiByPhone(@RequestParam ("phone") String phone){
    int count=0;
    for (int i=0; i<taxiList.size();i++){
        if ((taxiList.get(i).getPhone()).equals(phone)){
            count++;
        }
    }
    return "found "+count;
}
@RequestMapping(value ="/getTaxiPhone",method = RequestMethod.GET)
public @ResponseBody
String getAllTaxi(@RequestParam ("id") int id){
    return taxiList.get(id).getPhone();
}

@RequestMapping(value ="/getAllTaxi",method = RequestMethod.GET)
public @ResponseBody
List<Taxi> getAllTaxi(){
    return taxiList;
}

例如 getTaxi?id=2 返回 {"taxi_city_id":[55000001,67000001],"taxi_id":1113,"taxi_name":"zxcv","taxi_phon‌​e":"+73812999997"} ,但如果你尝试 getTaxiByPhone 呢? phone=+73812999997 您将找不到任何对象,因为如果您尝试返回带有计数的电话参数(return "found "+count+"for phone"+phone;),您将看到found 0 for phone 73812999997。这意味着 spring 解析 url 时符号“+”丢失了。

最佳答案

我认为这可能是特殊字符的问题,因为您在请求中传递了带有“+”的电话号码。 URL get 请求中的 + 号用于表示您应该转义的空格,可能使用

%2B

source

关于java - Spring请求参数中的特殊符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23792928/

相关文章:

java - 如何使用 Rest API 和 Java 在 Egnyte 中上传 pdf 文件

java - 如何在java中获取.exe文件的最后 'n'字节?

java - 如何创建多模块 Spring Boot Maven 项目?

java - 如何使用批处理文件在cmd提示符中输入文本

java - org.openqa.selenium.InvalidArgumentException : unknown error: unsupported protocol

java - 为 JUnit 测试重置静态字段

java - Spring quartz : Job does not fire

java - 跳过 Spring 中的 CORS 并配置项目以使用 Aptana

java - 请求的资源上不存在 'Access-Control-Allow-Origin' header ,并且 JWT token 不以 Bearer String 开头

java - 不同区域的日期/时间问题