通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过

@PathVariable("xxx") 绑定到操作方法的入参中。

一般与@RequestMapping(method = RequestMethod.GET)一起使用

@RequestMapping("/getUserById/{name}")
    public User getUser(@PathVariable("name") String name){
        return userService.selectUser(name);
    }
若方法参数名称和需要绑定的uri中变量名称一致时,可以简写:
@RequestMapping("/getUser/{name}")
    public User getUser(@PathVariable String name){
        return userService.selectUser(name);
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-01-01
  • 2022-01-18
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-09-05
  • 2021-07-21
  • 2022-12-23
相关资源
相似解决方案