首页 > 其他 > 详细

@RequestParam加与不加的区别

时间:2018-10-14 16:06:04      阅读:159      评论:0      收藏:0      [点我收藏+]

加上的情况:

    @RequestMapping("demo")
    public void test(@RequestParam String name){
        
    }

访问localhost:8080/demo,没有带上参数,会报错。可以通过设置@RequestParm里面的属性required属性为false,设置后不传参数也不会报错。

还可以指定属性defaultValue,如果设置了这个属性,没有设置required属性(即为true的情况下)。如果没有传参数,该参数会设置为defaultValue值

    @RequestMapping("demo")
    public void test(@RequestParam(defaultValue = "leo") String name){

    }

 

不加的时候:

    @RequestMapping("demo")
    public void test(String name){

    }

访问localhost:8080/demo,传不传参数name,都可以正常访问。

@RequestParam加与不加的区别

原文:https://www.cnblogs.com/tinyj/p/9786131.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!