我有
@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_phone":"+73812999997"}
,但如果你尝试 getTaxiByPhone 呢? phone=+73812999997
您将找不到任何对象,因为如果您尝试返回带有计数的电话参数(return "found "+count+"for phone"+phone;
),您将看到found 0 for phone 73812999997
。这意味着 spring 解析 url 时符号“+”丢失了。
最佳答案
关于java - Spring请求参数中的特殊符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23792928/