java - When to go for @RequestParam and @PathVariable -


just curious know in scenario should go @requestparam , @pathvariable. know that:

  1. @requestparam takes parameter value whereas @pathvariable takes placeholder value
  2. @requestparam can optional (required=false) while making request whereas @pathvariable value has provided.
  3. when want use @requestparam have know property syntax @pathvariable not required

is there other reason go specific one?

use @pathvariable if want adhere 'statefull' urls.

for example:-

/customer/:id   customer view/edit page /customer/      customer add page /customer/list  list customer page /customer/:cid/order  order of customer /customer/:cid/order/:oid  specific order of partucular customer. 

wisely using path variable result in url gives hint/clue resulting view/page means.

this lets support refresh,back & forward operation no effort.

@requestparams can used exatract data not passed path params. mvc handler can have combination of 2 required.


Comments