解决@PathVariable参数接收不完整的问题
今天遇到的问题是:
发送url参数接收不完整导致程序报错
http://localhost:8080/ddoe-control-center/orm/base/detail/com.sitech.ddoe.client.api.objopt.sample.Student
动态参数是com.sitech.ddoe.client.api.objopt.sample.Student
由于有分隔符.导致接收到的参数少了一部分,
解决办法:
1
2
3
4
|
@RequestMapping ( "/base/detail/{dataObjectId:.+}" )
public ModelAndView detailDataObject( @PathVariable String dataObjectId) {
.....
}
|
参考文档:
@PathVariable出现点号”.”时导致路径参数截断获取不全的解决
@PathVariable接受的参数可能为null
1
2
3
4
5
|
@RequestMapping (value = { "/getTreeNode/{id}" , "/getTreeNode" }, produces = "application/json;charset=UTF-8" , method = RequestMethod.POST)
@ApiOperation ( "查询树节点接口" )
public List<ModelTreeDto> getTreeNode( @PathVariable (value = "id" ,required= false ) String id) throws Exception {
return modelTreeServiceImpl.getTreeNode(id);
}
|
1.加上required=false,
2.在mapping上加上"/getTreeNode",这样可以使required=false生效,当没有传参时会请求/getTreeNode
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/Aurora_sss/article/details/78850599