当前位置:网站首页>requestparam注解接的收的是什么格式(玄机赋注解)
requestparam注解接的收的是什么格式(玄机赋注解)
2022-08-02 13:19:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
1、作用:
@RequestParam:将请求参数绑定到你控制器的方法参数上(是springmvc中接收普通参数的注解)2、语法:
语法:@RequestParam(value=”参数名”,required=”true/false”,defaultValue=””)
value:参数名
required:是否包含该参数,默认为true,表示该请求路径中必须包含该参数,如果不包含就报错。
defaultValue:默认参数值,如果设置了该值,required=true将失效,自动为false,如果没有传该参数,就使用默认值3、业务处理Controller
@Controller
@RequestMapping("hello")
public class HelloController2 {
/**
* 接收普通请求参数
* http://localhost:8080/hello/show16?name=linuxsir
* url参数中的name必须要和@RequestParam("name")一致
* @return
*/
@RequestMapping("show16")
public ModelAndView test16(@RequestParam("name")String name){
ModelAndView mv = new ModelAndView();
mv.setViewName("hello2");
mv.addObject("msg", "接收普通的请求参数:" + name);
return mv;
}
/**
* 接收普通请求参数
* http://localhost:8080/hello/show17
* url中没有name参数不会报错、有就显示出来
* @return
*/
@RequestMapping("show17")
public ModelAndView test17(@RequestParam(value="name",required=false)String name){
ModelAndView mv = new ModelAndView();
mv.setViewName("hello2");
mv.addObject("msg", "接收普通请求参数:" + name);
return mv;
}
/**
* 接收普通请求参数
* http://localhost:8080/hello/show18?name=998 显示为998
* http://localhost:8080/hello/show18?name 显示为hello
* @return
*/
@RequestMapping("show18")
public ModelAndView test18(@RequestParam(value="name",required=true,defaultValue="hello")String name){
ModelAndView mv = new ModelAndView();
mv.setViewName("hello2");
mv.addObject("msg", "接收普通请求参数:" + name);
return mv;
}
}4、测试:
参考地址:https://blog.csdn.net/sswqzx/article/details/84195043
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/125420.html原文链接:https://javaforall.cn
边栏推荐
- 你知道图论的spfa吗?
- Closures in JS
- 方正璞华“劳动人事法律自助咨询服务平台”在武汉武昌区投入使用!
- ETL(二):表达式组件的使用
- PGSQL database to realize the import and export
- Introduction to Graph Neural Networks (GNN) "Recommended Collection"
- 单例模式的七种写法,你都知道吗?
- SQL Server 2019 installation error 0 x80004005 service there is no timely response to the start or control request a detailed solution
- [b01lers2020]Welcome to Earth-1
- [C language] Analysis of function recursion (1)
猜你喜欢
随机推荐
暑假集训-week2图论
RISC-V instruction format and 6 basic integer instructions
【C语言】手撕循环结构 ——do...while语句及循环练习题(1)
A powerful js pop-up alert plugin
Article 48 - Analysis of timestamp2 parameters【2022-08-01】
Enterprise Network Planning Based on Huawei eNSP
你真的懂单例模式么
网络流详解(流网图一般能够反映什么信息)
Mysql视图
路由-Tab切换页面
SQL Server 2014 installation tutorial (nanny-level graphic tutorial)
麻烦问一下,对mysql 场景注入故障,是不是不是对mysql server 端注入故障,只是对ja
移动端适配,华为浏览器底色无法正常显示
【C语言】函数哪些事儿,你真的get到了吗?(2)
sql concat() function
tinymce-plugins
Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。
RestTemplate use: set request header, request body
How to improve the originality of self-media creation and create popular works?
How to do short video food from the media?5 steps to teach you to get started quickly









