java.lang.IllegalStateException: PathVariable/RequestParam annotation was empty on param 0.

这个异常是我在启动Spring项目时遇到的,然后报这个异常导致项目启动不起来,解决方法:
在@PathVariable这个注解后面加上value值。
这个是我报异常的代码:

    @GetMapping("/user/{id}")
    CommonResult<User> getUser(@PathVariable Long id);

    @GetMapping("/user/getByUsername")
    CommonResult<User> getByUsername(@RequestParam String username);

这个是修改后的代码

    @GetMapping("/user/{id}")
    CommonResult<User> getUser(@PathVariable("id") Long id);
    
    @GetMapping("/user/getByUsername")
    CommonResult<User> getByUsername(@RequestParam("username") String username);

猜你喜欢

转载自blog.csdn.net/SuperstarSteven/article/details/110136377