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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>