@Differences between requestparam and @ pathvariable and their application scenarios

@There is little difference between requestparam and @ pathvariable, mainly because the requested URL is different

When requesting an interface with @ requestparam, the URL is: http://www.test.com/user/getUserById?userId=1

When requesting an interface with @ pathvariable, the URL is: http://www.test.com/user/getUserById/2

(1) @ pathvariable example:

The main application scenario is: many applications use @ pathvariable in order to realize the restful style.

For example, CSDN:

Of course, sometimes this method is not used for restful style. Sometimes I think? The parameter passing methods such as userid = 1 & & status = 1 are not particularly good-looking or uncomfortable.

(2) @ requestparam example:

Application scenario: this method is also widely used, such as CSDN or blog Garden. There is no mapping here. You can see it by browsing blogs and news frequently.

Finally, if you ask me which method is better, my answer is to use one or a combination of them according to the needs of the business scenario. But they all have one thing in common, that is, they are visible.

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
分享
二维码
< <上一篇
下一篇>>