I know that if a parameter looks like this:
@RequestParam("userId") String userId
I can get the value by calling this:
requestParam.value()
But if I don't specify a name, Spring automatically uses the variable name. Like this:
@RequestParam String userId
If the param name isn't specified, how can I access it? I know its possible because Spring does it somehow, but requestParam.value() is blank in this case.
Spring doesn't populate the request based on the @RequestParam. Rather it populates the method argument annotated with @RequestParam (in a method annotated with @RequestMapping). The parameter given to the @RequestParam annotation tells Spring the name of the request parameter you want it to use as that argument. If you don't provide one, Spring defaults to using the name of the argument (so the 2 examples you give in your question are equivalent).
If you are trying to access a request parameter, you need to know the name of it, regardless of the framework you are using.
Recommend you not to do it that way.Spring use asm to analysis the java bytecode file,and extract parameter name of a method.But some time this does not work,because some .class file does not comprise parameter name,just parameter types,it depends on compiler options.
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