I'm confused with the behavior of @RequestParam(value="someValue")
.
In the docs it is said that
When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations - such as @RequestMapping and @SessionAttributes - on the controller interface rather than on the implementation class.
If I place @RequestParam
on my controller interface its value
is totally ignored (and therefore mapped value is null
if parameter name is different from the received parameter name), but defaultValue
and required
work ok.
If I place @RequestParam
on my controller implementation, everything works fine.
I read this answer, but I cannot understand why some parameters work while others don't and why docs are wrong.
Code example:
interface:
@RequestMapping(method = RequestMethod.GET)
List<MyObject> get(
//works if parameter in request has name "userName", which is not correct
@RequestParam(value = "username", required = false) String userName,
@RequestParam(value = "searchValue", required = false) String searchValue,
@RequestParam(value = "someId", required = false) Integer someId);
implementation:
@Override
public List<MyObject> get(
String userName,
String searchValue,
Integer someId) {
return myService.get(userName, searchValue, someId);
}
This finally should be resolved: https://jira.spring.io/browse/SPR-11055?focusedCommentId=160889&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-160889
Juergen Hoeller added a comment - Yesterday
I'm happy to report that this is finally resolved in master now, in time for the 5.1 RC1 release!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With