上海门户网站的亮点,网站开发平台及常用的开发工具,网站建设制作文字教程,东莞松山湖学校PathVariable
用于获取URL路径中的参数值
通过 PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中#xff1a;URL 中的 {xxx} 占位符可以通过PathVariable(“xxx”) 绑定到操作方法的入参中。
一般与RequestMapping(method RequestMethod.GET)一起使用
…PathVariable
用于获取URL路径中的参数值
通过 PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中URL 中的 {xxx} 占位符可以通过PathVariable(“xxx”) 绑定到操作方法的入参中。
一般与RequestMapping(method RequestMethod.GET)一起使用
RequestMapping(/getUserById/{name})
public User getUser(PathVariable(name) String name){return userService.selectUser(name);
}// 1 若方法参数名称和需要绑定的url中变量名称一致时,可以简写:
RequestMapping(/getUser/{name})
public User getUser(PathVariable String name){return userService.selectUser(name);
}// 2 若方法参数名称和需要绑定的url中变量名称不一致时写成:
RequestMapping(/getUserById/{name})
public User getUser(PathVariable(name) String userName){return userService.selectUser(userName);
}