当前位置:网站首页>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
边栏推荐
- How to do short video food from the media?5 steps to teach you to get started quickly
- 高效代码静态测试工具Klocwork 2022.2——Portal全新升级、支持RLM
- RestTemplate use: set request header, request body
- Scala基础语法入门(三)Scala中的各种运算符
- GCC版本升级到指定版本
- Ribbon负载均衡的深度分析和使用
- Redis all
- 冰箱“扩容”的战事,在今夏格外猛烈
- Based on the flask mall administrator functions
- MySQL - ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
猜你喜欢
二进制中1的个数
How to do short video food from the media?5 steps to teach you to get started quickly
方正璞华“劳动人事法律自助咨询服务平台”在武汉武昌区投入使用!
Intouch System Platform IDE-1
Article 48 - Analysis of timestamp2 parameters【2022-08-01】
RESTful 风格(详细介绍 + 案例实现)
SQL Server 2014 installation tutorial (nanny-level graphic tutorial)
In-depth analysis and use of Ribbon load balancing
吾爱第三课-修改版权和资源
【C语言】夏日一题 —— 求最大公约数和最小公倍数
随机推荐
String concatenation in SQL
Closures in JS
RestTemplate 使用:设置请求头、请求体
[C language] Analysis of function recursion (2)
Fabric.js 动态设置字号大小
Summer training camp-week2 graph theory
In-depth analysis and use of Ribbon load balancing
Wireless vibrating wire acquisition instrument remote modification method
PGSQL database to realize the import and export
this的绑定指向详细解答
How to implement waterfall flow layout (what is waterfall flow layout)
图论之Floyd,多源图最短路如何暴力美学?
如何通过DBeaver 连接 TDengine?
吾爱第三课-修改版权和资源
js array recursively use
【C语言】虐打循环练习题(2)
PHP+MYSQL [Student Information Management System] (Minimalist Edition)
Cannot determine loading status from target frame detached when selenium chrome driver is running
Set proxy server (Google+IE) "Recommended Collection"
百日刷题计划 ———— DAY1