当前位置:网站首页>@Detailed introduction of requestparam annotation
@Detailed introduction of requestparam annotation
2022-07-27 21:37:00 【m0_ sixty-seven million three hundred and ninety-one thousand f】
@RequestParam (org.springframework.web.bind.annotation.RequestParam) Used to assign a specified request parameter to a formal parameter in a method .
There are three properties :
(1)value: Request parameter name ( You have to configure )
(2)required: Is it necessary to , The default is true, namely This parameter must be included in the request , If not included , An exception will be thrown ( Optional configuration )
(3)defaultValue: The default value is , If the value is set ,required Set automatically to false, Whether you have configured it or not required, What values are configured , All are false( Optional configuration )
1 For demonstration effect , First you need to create a test control class , Then create a test method ,_ As shown in the figure ,_____ Method to add a parameter ,____ At this time, the method parameter is not annotated

adopt idea Tool launch web project , Then access the test results through the browser , Without parameters, the obtained parameters are null, But the page can display normally , The request can be executed normally .

With parameters , Parameters can be obtained and printed normally

Let's compare the effect of adding annotations , But just add @RequestParam, Setting parameters without any annotations .

Visit the browser again to see the effect , Bring it now userName The parameter page can display and print the result value normally , But as the picture shows , Without parameters , Page error reporting , return 400, And prompt userName non-existent


Of course, such restrictions are optional ,@RequestParam Add in required=false To turn off the limit of required parameters , This is the same as the first effect without annotation


@RequestParam It can also be used when the parameter is empty , Set the default value of a parameter for us , As shown in the figure , You can see it , Without parameters , What you get is the default value

Of default parameters key Name is the name of the parameter in the method , But through @RequestParam You can customize another , Because under certain conditions , The method name is fixed and cannot be modified , But the request parameter needs to pass another parameter key Name to pass on , This can be achieved in such a way


边栏推荐
- 30分钟彻底弄懂 synchronized 锁升级过程
- 报表设计丨如何让你的PowerBI看板出彩?
- Who is the sanctity of the six Chinese enterprises newly sanctioned by the United States?
- @Autowired注解与@Resource注解的区别
- Can single mode and multi-mode of industrial switches replace each other?
- Implicit intent
- MySQL back to table, SQL optimization, four isolation levels, three logs binlog, redo log, undo log
- What are the product performances of industrial Ethernet switches?
- 图解 SQL,这也太形象了吧!
- Can China make a breakthrough in the future development of the meta universe and occupy the highland?
猜你喜欢

The solution that the laptop can connect to WiFi but the browser cannot open the web page

微软商店无法下载应用,VS2019无法下载插件问题解决方案

What are the product performances of industrial Ethernet switches?

中英文说明书丨人甲胎蛋白(AFP)ELISA定量试剂盒

Pytest failed and rerun
![Paper appreciation [aaai18] meta multi task learning for sequence modeling](/img/2b/345b5a287fcd9c9b1a86ae683f124b.png)
Paper appreciation [aaai18] meta multi task learning for sequence modeling

A new technical director asked me to do an IP territorial function~

The new CTO strongly prohibits the use of calendar?

PostgreSQL source code (65) analysis of the working principle of globalvis, a new snapshot system

IDEA连接MySQL数据库并执行SQL查询操作
随机推荐
Understanding of reg type variables in Verilog HDL
Commercial delay of self-developed 5g chip? Apple iPhone will adopt Qualcomm 5g chip in the next four years
A new technical director asked me to do an IP territorial function~
Daily Mathematics Series 60: February 29
What are the product performances of industrial Ethernet switches?
ACM mm 2022 | Zhejiang University proposed: point cloud segmentation, active learning of new SOTA
30分钟彻底弄懂 synchronized 锁升级过程
对L1正则化和L2正则化的理解[通俗易懂]
When accessing the shared folder, you will be prompted "because file sharing is not secure smb1 Protocol". Please use Smb2 protocol
ECCV 2022 | China University of science and Technology & jd.com proposed: data efficient transformer target detector
Behavior level description and RTL level description
Dual process theory and triple mental model
Samsung's most advanced EUV production line has been put into operation: the 7Nm capacity this year will be three times that of last year
Thinking about SLA of cloud computing
聊聊 MySQL 事务二阶段提交
软件测试面试题:请说出这些测试最好由那些人员完成,测试的是什么?
2019q4 memory manufacturers' revenue ranking: Samsung fell 5%, only SK Hynix and micron maintained growth
The solution that the laptop can connect to WiFi but the browser cannot open the web page
STL源码剖析
软件测试面试题:单元测试、集成测试、系统测试的侧重点是什么?