王國慶 发表于 2024-7-30 07:01:37

【SpringBoot】参数转达

1.定义URL变量
@RequestMapping("/user/{username}")
@ResponseBody
public String userProfile(@PathVariable String username){
    return "user:"+username;
}

2.定义多个URL变量
@RequestMapping("/user/{username}/blog/{blogId}")
@ResponseBody
public String getUserBlog (@PathVariable String username,@PathVariable int blogId){
    return "user:"+username+"blog:"+blogId;
}8

.3.匹配正则表达式
@RequestMapping("/user/{username:}/blog/{blogId}")
@ResponseBody
public String getUserBlog(@PathVariable String username,@PathVariable int blogId){
   return ”user:“+username+"blog:"+blogId;
}12



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 【SpringBoot】参数转达