@RequestParam注解的作用及用法

最简单的两种写法,在写接口时:加或不加@RequestParam注解的区别

@RequestParam注解的作用及用法_第1张图片

第一种写法参数为非必传,第二种写法参数为必传。参数名为userId

第二种写法可以通过@RequestParam(required = false)设置为非必传。因为required值默认是true,所以默认必传

第二种写法可以通过@RequestParam("userId")或者@RequestParam(value = "userId")指定参数名

第二种写法可以通过@RequestParam(defaultValue = "0")指定参数默认值

用法如下:

转载于:https://www.cnblogs.com/zlw-xf/p/9464929.html

你可能感兴趣的:(@RequestParam注解的作用及用法)