spring | @RequestParam 发表于 2022-11-17 更新于 2023-01-25 分类于 java , spring , spring boot , 注解 , Controller 阅读次数: Valine: @RequestParam 注解的用法 demo1234@GetMapping("/list")public String test(@RequestParam int userId) { return "list";} 讲解如下123@RequestParam(required = false)设置为非必传。因为required值默认是true,所以默认必传@RequestParam("userId")或者@RequestParam(value = "userId")指定参数名。@RequestParam(defaultValue = "0")指定参数默认值 用法如下1234@GetMapping("/list")public String test(@RequestParam(value = "userId", defaultValue = "0", required = false) int userId) { return "list";} 请我喝杯咖啡吧~ 打赏 微信支付 支付宝