2

In spring-mvc, the query for the controller call can be built using @RequestParam. If you don't supply the value, then it defaults to the method parameter name.

example :

@RequestMapping("/hello")
@ResponseBody
public String hello(@RequestParam String name)
{
    return "hello "+name; 
}

is mapped to

/hello?name=x 

My question is this. How does spring bind this information (or even access it) ? Arent parameter names discarded at runtime ? Does it use some library like paranamer ?

MikePatel
  • 2,593
  • 2
  • 24
  • 38

1 Answers1

2

It only works if you have debug enabled when you compile the class as here. Then the compiler keeps the info.

As part of one of the last spring releases they extended this to include constructors. Seems mighty flakey to me - if you forget to add the debug option then your app stops working!

So one possible way (with debug set to true) seems to be to use bytecode manipulation and there is this example of getting them when using asm. I don't know if this is the same way Spring does it.

Community
  • 1
  • 1
plasma147
  • 2,191
  • 21
  • 35
  • Perhaps @RequestParam("name") will work even without the debug option – Bertie Jul 03 '12 at 17:53
  • Yes it does - because you are explicitly providing the name and we can inspect the annotation and it's value at runtime as it has runtime retention. – plasma147 Jul 04 '12 at 08:52