samedi 21 février 2015

Some clarification about Spring @PathVariable annotation?

I have the following doubt using the path variable in Spring MVC.


So I have a method like this:



@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.GET)
@ResponseBody
public Account accountDetails(@PathVariable("accountId") int id) {
return retrieveAccount(id);
}


This method handle Http Request like this one:



http://localhost:8080/rest-ws/app/accounts/0


It is pretty clear to me that the 0 into the URL become the id input parameter but my doubt is: why in this example the path variable have a name ("accountId")?


I think that I can do something like this:



public Account accountDetails(@PathVariable int id)


or not?


Aucun commentaire:

Enregistrer un commentaire