当前位置:网站首页>@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


边栏推荐
- How to check whether there is Tsinghua source / delete Tsinghua source and keep the default source
- JVM-内存模型 面试总结
- Plato Farm在Elephant Swap上铸造的ePLATO是什么?为何具备高溢价?
- ADB ~ hide or disable the status bar and virtual keys
- Report design - how to make your powerbi Kanban brilliant?
- Ziguang zhanrui: dozens of 5g terminals based on chunteng 510 will be commercially available in 2020
- Comprehensively design an oppe homepage -- Design of selected accessories on the page
- Qmodbus library is used, and it is written as ROS node publishing topic and program cmakelist
- 监听服务器jar运行,及重启脚本
- Worthington血浆胺氧化酶 (PAO) 说明书
猜你喜欢

Characteristics of exonuclease in Worthington venom and related literature

ECCV 2022 | China University of science and Technology & jd.com proposed: data efficient transformer target detector

Puzzle (021) eliminate problems

单核CPU, 1G内存,也能做JVM调优吗?

What are the product performances of industrial Ethernet switches?

ZABBIX monitoring service (III) configuration management graphics and windows

Explain cache consistency and memory barrier

Search, insert and delete of hash table

The new CTO strongly prohibits the use of calendar?

微软商店无法下载应用,VS2019无法下载插件问题解决方案
随机推荐
简单手动实现Map
[day_4-review, basic concepts of objects and arrays - 1]
技术管理 - 一定要抓大放小
When accessing the shared folder, you will be prompted "because file sharing is not secure smb1 Protocol". Please use Smb2 protocol
Mysql 数据恢复流程 基于binlog redolog undolog
Worthington血浆胺氧化酶 (PAO) 说明书
软件测试面试题:什么是回归测试?
单核CPU, 1G内存,也能做JVM调优吗?
[what subjects does Huawei hcie security test? What knowledge points does Huawei hcie security test have?]
软件测试面试题:假设有一个文本框要求输入10个字符的邮政编码,对于该文本框应该怎样划分等价类?
Characteristics and determination scheme of Worthington mushroom polyphenol oxidase
Understanding of reg type variables in Verilog HDL
一篇文章带你走进pycharm的世界----别再问我pycharm的安装和环境配置了!!!
ACM MM 2022 | 浙大提出:点云分割主动学习新SOTA
Report design - how to make your powerbi Kanban brilliant?
crsctl中,显示的HOME的作用
The application of building cloud rendering is expanding, and more and more industries are in urgent need of visualization services
一文读懂Plato Farm的ePLATO,以及其高溢价缘由
app测试定位方式
递归/回溯刷题(上)