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

What if the @ RequestParam parameter is lost occasionally

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail what to do when the @ RequestParam parameter is occasionally lost. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The @ RequestParam parameter is missing

After changing a version of the code, it is found that the parameters of the @ RequestParam annotation are often lost.

First of all, make sure that the front end does pass the parameters, and use curl to request the interface directly. It is found that sometimes the parameters are lost. After rebooting, you use curl to request an interface with missing parameters. No matter how much you try again, there will be no problem.

There is no choice but to go to the source code of tomcat, because the parameter @ RequestParam will take the corresponding value from the request.getParameterMap () method, and then make a breakpoint to see how tomcat gets it.

Finally follow this class to implement the method

Finally, we go to the getParameters method of coyoteRequest, and the implementation is very simple.

Then getParameterNames ()

Final processing of query parameters

In the end, it is parsed from the parameter queryMB, and this queryMB is the parameter passed when the request is made.

Let's see if queryMB is empty when getParameterMap is empty, to determine that tomcat must have received the parameter.

Then found that queryMB has a value, but it seems that the above method did not parse this parameter, began to suspect that some interface must have changed something, because Request can be recycled, but the request is used again must be the end of the request, later suspected to be the use of deferedResult, but also excluded, because deferedResult will use the asynchronous mode above servlet3.0, request will not be recycled in advance

Puzzled while reading this article suddenly enlightened, (later found that there is an import function is more time-consuming, was put in a pure asynchronous method, access to the method has been cut off a method, and which got request.getParameter) request can be passed to the asynchronous thread, but to ensure that before the request to return access, such as before the deferedResult set value. In order to avoid this, try not to send it to the asynchronous thread.

The usage precautions of @ RequestParam

@ RequestParam: bind the request parameter to the method parameter of your controller (is the note to receive the normal parameter in springmvc)

For example:

If the Value attribute of your @ RequestParam is pId, then the requested link is

Http://localhost:8080/api/findBByParkId?pId=1

@ RequestParam property

Value / name: name in the request parameter (required parameter)

Required: whether this parameter is required in the request parameters. The default is true,true. Default is required.

Value: default value test succeeded

Be careful

This is the end of the article on "what if the @ RequestParam parameter is occasionally lost". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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

Development

Wechat

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

12
Report