问题:在spring boot中使用rest API风格调用接口,参数出现带特殊字符的数据,如姓名xx.yy,或者,号分割的字符串
例如:
http://localhost:8080/business/joinbiz/xx.yy
http://localhost:8080/business/joinbiz/x,y
正常接收的话:
@RequestMapping(value = "/joinbiz/{misId}", method = RequestMethod.GET)
public BizInfo getBizInfo(@PathVariable String misId){
try {
···
resultMap = businessDsnRelationService.getBizInfosByMis(misId);
···
} catch (Exception e){
···
}
}
这样接收到的misId的参数的值为xx,并没有获取到点后面的yy参数
原因:
springmvc把点当做后缀了,因此只可以获取后缀前的数据
解决办法:
在RequestMapping上使用正则匹配:
@RequestMapping(value = "/joinbiz/{misId:.+}", method = RequestMethod.GET)
public Map<String, Object> getBizInfo(@PathVariable String misId){
try {
···
resultMap = businessDsnRelationService.getBizInfosByMis(misId);
···
} catch (Exception e){
···
}
}
本文探讨了在SpringBoot中使用REST API风格调用接口遇到的问题,当URL路径参数包含特殊字符如点号或逗号时,如何正确接收这些参数。通过使用正则表达式改进@RequestMapping注解,实现对带有特殊字符参数的有效处理。
1094

被折叠的 条评论
为什么被折叠?



