Java – when to @ requestparam and @ pathvariable
Just want to know in which case we should select @ requestparam and @ pathvariable I Know:
>@ requestparam takes the parameter value and @ pathvariable takes the placeholder value > @ requestparam can be optional when making a request (required = false), but the @ pathvariable value must be provided. > When we want to use @ requestparam, we must know the attribute syntax, but we don't need @ pathvariable
Is there any other reason to go specific?
Solution
If you want to follow the "statefull" URL, use @ pathvariable
For example:-
/customer/:id Customer view/edit page /customer/ Customer Add page /customer/list List Customer Page /customer/:cid/order All order of a Customer /customer/:cid/order/:oid Specific order of a partucular Customer.
Using path variables wisely will cause URLs to provide hints / clues about the meaning of the result view / page
@Requestparams can be used to extend data that is not passed as a path parameter Your MVC handler can combine two as needed