
RequestParam用来接收http请求传递过来的请求参数例如xxx/data1?accountzhangsanpage100genderboyhbseathbsaahbsbjbGetMapping(data1) public String data1(RequestParam(value account) String username, RequestParam(required false, defaultValue 1) int page, String gender, RequestParam ListString hbs){1、如果前端传递的请求参数名和controller方法的参数名不一致必须显示指定接收前端的请求参数名。 如前端传递的请求参数名为account后端接收该请求参数的参数名为username。则需要在RequestParam中指定接收的参数名RequestParam(value account)意思是把前端传过来的account赋值给username。2、RequestParam的required参数默认值为true。表示前端必须传此参数不传报400异常。改为false后前端可以不传此参数如果不传后端参数就接收不到参数值就会给参数值赋值为null。此时如果定义的数据类型为 int 这种的值类型就会报错。null不能赋给int类型。可以将其改成Integer这种引用类型。defaultValue是参数的默认值如果前端不传后端参数就使用默认值。3、若前端传递的参数名和后端方法的参数名一致也可以省略RequestParam注解。4、当从前端接收一个list集合时省略RequestParam注解会报错。如果不使用RequestParam注解也可以自己手动取参public String list(HttpServletRequest request) { String current request.getParameter(current); String pageSize request.getParameter(pageSize); return current current , pageSize pageSize;