【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException

慈云数据 1年前 (2024-03-21) 技术支持 77 0

报错一:

【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException
(图片来源网络,侵删)

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

原因

【SpringBoot项目报错】org.springframework.web.bind.MissingPathVariableException
(图片来源网络,侵删)
@GetMapping("/getInfo")
public BaseRespoNSE getInfo(@PathVariable("id") Long id){
    return xxx;
}

postman ->;  HTTP://IP:prot/xxxxx/getInfo?id=1

解决方法有两种:

一、@PathVariable 改为 @RequestParam 即可

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

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

报错二:

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

微信扫一扫加客服

微信扫一扫加客服

点击启动AI问答
Draggable Icon