SpringBoot 和 Vue 参数类型不对应,导致method parameter is not present

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){

}

猜你喜欢

转载自blog.csdn.net/MyFreeIT/article/details/131959500