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

目录

  • 解决@PathVariable参数接收不完整的问题
    • 今天遇到的问题是:
    • 解决办法:
  • @PathVariable接受的参数可能为null

    解决@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 = https://www.it610.com/article/{"/getTreeNode/{id}","/getTreeNode"}, produces = "application/json; charset=UTF-8", method = RequestMethod.POST)@ApiOperation("查询树节点接口")public List getTreeNode(@PathVariable(value = "https://www.it610.com/article/id",required=false ) String id) throws Exception {return modelTreeServiceImpl.getTreeNode(id); }

    1.加上required=false,
    【解决@PathVariable参数接收不完整的问题】2.在mapping上加上"/getTreeNode",这样可以使required=false生效,当没有传参时会请求/getTreeNode
    以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

      推荐阅读