Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Note @ RequestParam what is the difference between adding and not adding

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

I would like to share with you the difference between adding and not adding @ RequestParam. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it together.

To demonstrate the effect, you first need to create a test control class and then create a test method

As shown in the figure, a parameter is added to the method, and the method parameter is not annotated.

At this point, if the access to aabbb does not pass name, it returns something like this

If you add @ RequestParam, you will get an error.

Of course, this restriction is optional. Add required=false to @ RequestParam to turn off the restriction of required parameters, which will have the same effect as without the first unannotated parameter.

@ RequestParam can also set the default value of a parameter for us when the parameter is empty. As shown in the figure, you can see that in the absence of a parameter, what you get is the default value.

seven

The key name of the default parameter is the parameter name in the method, but another can be customized through @ RequestParam, because under some conditions, the method name is fixed and cannot be modified, but the requested parameter needs to be passed through another parameter key name, so it can be implemented in this way.

The above is all the content of this article entitled "what's the difference between adding and not adding @ RequestParam". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report