相关推荐recommended
【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException
作者:mmseoamin日期:2023-11-30

报错一:

【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException,【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException,第1张

org.springframework.web.bind.MissingPathVariableException: Required URI template variable 'id' for method parameter type Long is not present

原因:

@GetMapping("/getInfo")
public BaseResponse getInfo(@PathVariable("id") Long id){
    return xxx;
}

postman ->  http://ip:prot/xxxxx/getInfo?id=1

解决方法有两种:

【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException,【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException,第2张

一、@PathVariable 改为 @RequestParam 即可

二、@GetMapping("/getInfo") 改为 @GetMapping("/getIn/{id}")

        postman ->  http://ip:port/xxxxx/getInfo/1

报错二:

【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException,【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException,第3张

org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'ids' for method parameter type Long[] is not present

原因:
@DeleteMapping("/delete")
public BaseResponse delete(@RequestParam("ids") Long[] ids) {
    return xxx;
}

解决方法:

@RequestParam 改为 @PathVariable ,@DeleteMapping("/delete") 改为 @DeleteMapping("/delete/{ids}")

 postman ->  http://ip:port/xxxxx/delete/122222,3333334

 postman ->  http://ip:port/xxxxx/delete/166666