-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Allow @RequestParam, @PathVariable, and their siblings on fields #23618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue is a possible duplicate of #23094 and #21770, but I would really like to see it implemented. Not only will it solve the issue with shortened parameter names, but it would also allow us to construct a POJO from headers/parameters with names that are not legal Java identifiers (for example "x-cf-applicationid"). |
Also related: #22047. |
Hi, could you provide any recommendation on how to start proceeding with this feature? |
Hi, I'm new here. I'm wondering if is it a good idea to introduce a new annotation like public SomeResponse search(@RequestParam SearchRequest request) {
...
}
public class SearchRequest {
@ParamName("q")
private String query;
@ParamName("q")
private String year;
@ParamName("q")
private String language;
} |
We have no plans to introduce field-level request binding annotations. |
This comment was marked as duplicate.
This comment was marked as duplicate.
It would be great if this is supported by default, but you can achieve the same thing with custom method argument resolvers. You can read my solution from here: https://stackoverflow.com/a/79132213/13452926 |
It is common to use abbreviated names for query parameters in
GET
requests.For example:
Where
q
means query,y
means year, andl
means language.This can then be handled using a controller method:
where:
However if we could apply
@RequestParam
on fields, then we could makeSearchRequest
more readable:As shown in the linked SO post, it is possible to customize Spring to do this using a custom annotation (e.g.
@ParamName
), but I think it would be cleaner and more elegant to allow@RequestParam
(and@PathVariable
, etc.) on POJO fields.References
The text was updated successfully, but these errors were encountered: