加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 何时去@RequestParam和@PathVariable

发布时间:2020-12-14 05:51:58 所属栏目:Java 来源:网络整理
导读:只是想知道在哪种情况下我们应该选择@RequestParam和@PathVariable.我知道: @RequestParam采用参数值,而@PathVariable采用占位符值 @RequestParam在发出请求时可以是可选的(required = false),而必须提供@PathVariable值. 当我们想要使用@RequestParam时,我
只是想知道在哪种情况下我们应该选择@RequestParam和@PathVariable.我知道:

> @RequestParam采用参数值,而@PathVariable采用占位符值
> @RequestParam在发出请求时可以是可选的(required = false),而必须提供@PathVariable值.
>当我们想要使用@RequestParam时,我们必须知道属性语法,但不需要@PathVariable

有没有其他理由去特定的?

解决方法

如果要遵守“statefull”网址,请使用@PathVariable.

例如:-

/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.

明智地使用Path Variable将导致URL提供关于结果视图/页面的含义的提示/线索.

This also lets you support refresh,back & forward operation with no
extra effort.

@RequestParams可用于扩展未作为路径参数传递的数据.您的MVC处理程序可以根据需要组合使用两个.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读