Skip to content

AnnotationMappingDiscoverer should read @RequestMapping#params() #467

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

Closed
sp00m opened this issue Jul 19, 2016 · 1 comment
Closed

AnnotationMappingDiscoverer should read @RequestMapping#params() #467

sp00m opened this issue Jul 19, 2016 · 1 comment
Assignees
Labels
in: core Core parts of the project type: enhancement
Milestone

Comments

@sp00m
Copy link

sp00m commented Jul 19, 2016

@RequestMapping allows to use requests' GET parameters to map incoming requests without having to inject parameters into a @RequestParam annotated method parameter:

@RequestMapping(method = GET, value = "/foobar", params = { "!one", "two", "three!=3", "four=4" })
public ResponseEntity<?> get() {
  return foobar();
}

This is pretty useful when you want clean API endpoints as well as clean code (e.g. no need of single method delegating to other methods thanks to a switch/case on the parameter's value).

It could be great if linkTo(methodOn(FooBarApi.class).get()) took these params into account as well, by generating for the above example at least:

http://example.com/foobar?four=4

And why not:

http://example.com/foobar?four=4&two=true

But iff no @RequestParam matched this two parameter (otherwise, the actual value would have been given when calling linkTo(methodOn(FooBarApi.class).get(twoParamValue))).

What do you think about it?

Technically, when dealing with the @RequestMapping annotation, the AnnotationMappingDiscoverer instance used in ControllerLinkBuilderFactory could instantiate an new org.springframework.web.servlet.mvc.condition.ParamsRequestCondition to parse thoses params.

odrotbohm pushed a commit that referenced this issue Jul 14, 2021
…ms = …)

We now inspect the static request parameters declared in the actual request mapping and apply those values when building URIs pointing to those methods.

Original pull request: #1576.
odrotbohm added a commit that referenced this issue Jul 14, 2021
General house keeping.

Original pull request: #1576.
@odrotbohm
Copy link
Member

This should be in place thanks to @reda-alaoui's contribution. Minor comment on the original description: we do not add two=true as suggested as there's no value given in the params definition.

@odrotbohm odrotbohm self-assigned this Jul 14, 2021
@odrotbohm odrotbohm added in: core Core parts of the project type: enhancement labels Jul 14, 2021
@odrotbohm odrotbohm added this to the 1.4 M1 milestone Jul 14, 2021
odrotbohm added a commit that referenced this issue Nov 23, 2021
The commits for #467 significantly degraded performance as CachingMappingDiscoverer.getParams(Method) doesn't properly cache the result of the call which causes quite expensive, unnecessarily repeated annotation lookups for the very same method. We also avoid the creation of an Optional instance for the sole purpose of a simple null check.

Introduce FormatterFactory to potentially cache the to-String formatting functions and thus avoid repeated evaluation and Function object creation.

We now also avoid the creation of ParamRequestCondition instances if no @RequestParams(params = …) values could be found in the first place.
odrotbohm added a commit that referenced this issue Nov 23, 2021
The commits for #467 significantly degraded performance as CachingMappingDiscoverer.getParams(Method) doesn't properly cache the result of the call which causes quite expensive, unnecessarily repeated annotation lookups for the very same method. We also avoid the creation of an Optional instance for the sole purpose of a simple null check.

Introduce FormatterFactory to potentially cache the to-String formatting functions and thus avoid repeated evaluation and Function object creation.

We now also avoid the creation of ParamRequestCondition instances if no @RequestParams(params = …) values could be found in the first place.
odrotbohm added a commit that referenced this issue Nov 23, 2021
The commits for #467 significantly degraded performance as CachingMappingDiscoverer.getParams(Method) doesn't properly cache the result of the call which causes quite expensive, unnecessarily repeated annotation lookups for the very same method. We also avoid the creation of an Optional instance for the sole purpose of a simple null check.

Introduce FormatterFactory to potentially cache the to-String formatting functions and thus avoid repeated evaluation and Function object creation.

We now also avoid the creation of ParamRequestCondition instances if no @RequestParams(params = …) values could be found in the first place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants