org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'id' for method parameter type String is not present
客户端:
requestUserInfoById()
const requestUserInfoById = async (id?: string) => {
}

服务器端:
@GetMapping("/user/getUserProfile/{id}")
public UserVO getUserProfile(@PathVariable("id") String id,
HttpServletRequest request, HttpServletResponse response) {
}
解决方法:
public UserPO getUserInfoById(@RequestParam(name ="id",required=false)
String id,
HttpServletRequest request,
HttpServletResponse response){
}
当尝试访问缺少必要参数id的API时,服务器抛出MissingServletRequestParameterException异常。客户端函数requestUserInfoById没有传入id参数。服务器端注解使用了@PathVariable,而解决方案是改用@RequestParam,并设置required为false,以允许参数可选。
9207

被折叠的 条评论
为什么被折叠?



