@PathVariable
is to obtain some placeholder from the uri (Spring call it an URI Template) — see Spring Reference Chapter 16.3.2.2 URI Template Patterns@RequestParam
is to obtain an parameter — see Spring Reference Chapter 16.3.3.3 Binding request parameters to method parameters with @RequestParam
Assume this Url for the below code :
http://localhost:8080/MyApp/user/1234/invoices?date=12-05-2013
(to get the invoices for userId 1234 for today)@RequestMapping(value="/user/{userId}/invoices", method = RequestMethod.GET)
public List<Invoice> listUsersInvoices(
@PathVariable("userId") int userId,
@RequestParam(value = "date", required = false) Date dateValue) {
//userId value is 1234
//
dateValue value is 12-05-2013
...
}
No comments:
Post a Comment