Spring请求参数中的特殊符号

时间:2014-05-21 20:14:57

标签: 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,则找不到任何对象,因为如果您尝试使用count(return "found "+count+" for phone"+ phone;)返回phone参数,你会看到found 0 for phone 73812999997。这意味着签署&#39; +&#39;春天解析网址丢失了。

1 个答案:

答案 0 :(得分:1)

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

%2B

source