@RequestParam 注解

版权声明:技术有限,如有错误,请指出谢谢!作者:赵先森 出处:https://blog.csdn.net/weixin_37264997 版权所有,欢迎保留原文链接进行转载:) https://blog.csdn.net/weixin_37264997/article/details/84837313

本文讲解@RequestParam 注解 的用法

demo

@GetMapping("/list")
public String test(@RequestParam int userId) {
    return "list";
}

讲解如下

1.@RequestParam(required = false)设置为非必传。因为required值默认是true,所以默认必传
2.@RequestParam("userId")或者@RequestParam(value = "userId")指定参数名。
3.@RequestParam(defaultValue = "0")指定参数默认值

用法如下

@GetMapping("/list")
public String test(@RequestParam(value = "userId", defaultValue = "0", required = false) int userId) {
    return "list";
}

猜你喜欢

转载自blog.csdn.net/weixin_37264997/article/details/84837313