zoukankan      html  css  js  c++  java
  • @RequestParam加与不加的区别

    最简单的两种写法,加或不加@RequestParam注解
    
        @RequestMapping("/list")
        public String test(int userId) {
             
            return "list";
        }
         
         
        @RequestMapping("/list")
        public String test(@RequestParam int userId) {
             
            return "list";
        }
    
    第一种写法参数为非必传,第二种写法参数为必传。参数名为userId。
    
    第二种写法可以通过@RequestParam(required = false)设置为非必传。因为required值默认是true,所以默认必传。
    
    第二种写法可以通过@RequestParam("userId")或者@RequestParam(value = "userId")指定参数名。
    
    第二种写法可以通过@RequestParam(defaultValue = "0")指定参数默认值
    
    
    用法如下:
    
        @RequestMapping("/list")
        public String test(@RequestParam(value = "userId", defaultValue = "0", required = false) int userId) {
             
            return "list";
        }
  • 相关阅读:
    c++:函数模板
    1084 外观数列
    1083 是否存在相等的差
    1082 射击比赛
    1081 检查密码
    1080 MOOC期终成绩
    1079 延迟的回文数
    1078 字符串压缩与解压
    1077 互评成绩计算
    1076 Wifi密码
  • 原文地址:https://www.cnblogs.com/zouhong/p/11795775.html
Copyright © 2011-2022 走看看