当前位置:主页 > 软件编程 > JAVA代码 >

解决@PathVariable参数接收不完整的问题

时间:2021-11-28 11:30:43 | 栏目:JAVA代码 | 点击:

解决@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

由于有分隔符.导致接收到的参数少了一部分,

解决办法:

@RequestMapping("/base/detail/{dataObjectId:.+}")
public ModelAndView detailDataObject(@PathVariable String dataObjectId) {
        .....
    }

参考文档:

@PathVariable出现点号”.”时导致路径参数截断获取不全的解决

@PathVariable接受的参数可能为null

@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

您可能感兴趣的文章:

相关文章