For enhancements, provide context and describe the problem.
context&problem:
When I use webclient to request an http address with optional request parameters, even if I pass a null value to the optional parameter, the null value will be changed to an empty string in the final request
Can webclient automatically recognize the request parameter that is null, and then not display it in the request address?
Means that when'org_team' is null, the last request address is'/api/list_sla_instances?bu=%E9%85%92%E5%BA%97%E6%97%85%E6%B8%B8&bg=%E9 %85%92%E5%BA%97&dateKey=2020-10-29'
Comment From: rstoyanchev
@binggo-top it is preferable to post text rather than images. It's easier to see the necessary detail and more search friendly.
So you have a URI template such as "/path?org_team={org_team}"
and when expanding with an null
or an empty Optional
you want the query parameter to not appear at all.
It doesn't work like that because you already have org_team
as a literal in the template. It is also possible and legitimate to have a parameter with an empty value so there is no way for the framework to know whether you want that or no parameter to appear at all.
In 5.3 there is a new queryParamIfPresent(Optional)
method, based on #25951, so you could do:
webClient.get()
.uri("/path", builder -> builder.queryParamIfPresent("org_team", orgTeamOptionalValue))
Comment From: binggo-top
Thank you very much for your answers, I will try the method you mentioned above.