首页 \ 问答 \ 何时使用@QueryParam vs @PathParam(When to use @QueryParam vs @PathParam)

何时使用@QueryParam vs @PathParam(When to use @QueryParam vs @PathParam)

我没有问过这个问题: @PathParam和@QueryParam有什么区别?

这是一个“最佳做法”或惯例问题。

什么时候使用@PathParam vs @QueryParam

我可以想到的决定可能是使用这两种来区分信息模式。 让我在下面说明我的LTPO - 不太完美的观察。

PathParam使用可以保留用于信息类别,这将很好地落入信息树的一个分支。 PathParam可用于深入实体类层次结构。

而QueryParam可以被保留用于指定属性来定位类的实例。

例如,

  • /Vehicle/Car?registration=123
  • /House/Colonial?region=newengland

/category?instance

@GET
@Path("/employee/{dept}")
Patient getEmployee(@PathParam("dept")Long dept, @QueryParam("id")Long id) ;

vs /category/instance

@GET
@Path("/employee/{dept}/{id}")
Patient getEmployee(@PathParam("dept")Long dept, @PathParam("id")Long id) ;

vs ?category+instance

@GET
@Path("/employee")
Patient getEmployee(@QueryParam("dept")Long dept, @QueryParam("id")Long id) ;

我不认为有这样做的标准惯例。 在那儿? 不过,我想听听人们如何使用PathParam和QueryParam来区分他们的信息,就像上面的例子。 我也很乐意听到这个做法背后的原因。


I am not asking the question that is already asked here: What is the difference between @PathParam and @QueryParam

This is a "best practices" or convention question.

When would you use @PathParam vs @QueryParam.

What I can think of that the decision might be using the two to differentiate the information pattern. Let me illustrate below my LTPO - less than perfect observation.

PathParam use could be reserved for information category, which would fall nicely into a branch of an information tree. PathParam could be used to drill down to entity class hierarchy.

Whereas, QueryParam could be reserved for specifying attributes to locate the instance of a class.

For example,

  • /Vehicle/Car?registration=123
  • /House/Colonial?region=newengland

/category?instance

@GET
@Path("/employee/{dept}")
Patient getEmployee(@PathParam("dept")Long dept, @QueryParam("id")Long id) ;

vs /category/instance

@GET
@Path("/employee/{dept}/{id}")
Patient getEmployee(@PathParam("dept")Long dept, @PathParam("id")Long id) ;

vs ?category+instance

@GET
@Path("/employee")
Patient getEmployee(@QueryParam("dept")Long dept, @QueryParam("id")Long id) ;

I don't think there is a standard convention of doing it. Is there? However, I would like to hear of how people use PathParam vs QueryParam to differentiate their information like I exemplified above. I would also love to hear the reason behind the practice.


原文:https://stackoverflow.com/questions/11552248
更新时间:2022-04-21 13:04

相关问答

更多
  • 使用以下查询: ALTER TABLE tableName CHANGE `oldcolname` `newcolname` datatype(length); RENAME函数在Oracle数据库中使用。 ALTER TABLE tableName RENAME COLUMN "oldcolname" TO "newcolname" datatype(length); 注意用于MySQL的反引号,而双引号用于Oracle的语法 Use the following query: ALTER TABLE ...
  • 你使用set_index有或没有set_index inplace=True df.set_index(df.File.radd(df.index.astype(str) + '_')) Start File File 0_a 0 a 1_a 1 a 2_a 2 a 3_a 2 a 4_b 0 b 5_b 1 b 6_b 2 b 7_b 2 b 8 ...
  • 根据http://codingforums.com/showthread.php?t=148936 ,您可能需要解析SHOW CREATE TABLE的结果以获取当前定义,然后在ALTER语句中使用该定义。 mysql_fetch_field()也可能有用。 According to http://codingforums.com/showthread.php?t=148936, you may have to parse the results of SHOW CREATE TABLE to get th ...
  • 不,你做得对。 ALTER用于更改现有数据库对象(例如表的名称 - 它是数据定义语句(DDL))。 使用AS为结果提供别名,因此该语句: SELECT COUNT(*) AS num FROM TABLE_A 将计算表中的行数,并将结果输出到名为num的列中。 请注意,除非您指定计数,否则计数不适用于不同的行,或者使用group by子句,因此如果存在重复行,则它们都将被计算。 No, you've got it right. ALTERis used to change existing databas ...
  • 无法重命名索引。 随意在Azure Search UserVoice网站上添加建议。 It's not possible to rename an index. Feel free to add a suggestion on Azure Search UserVoice site.
  • 我不确定MySQL是否允许首先为主键命名。 虽然似乎有一种语法: CREATE TABLE test ( test_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, CONSTRAINT my_test_pk PRIMARY KEY (test_id) ) ENGINE=InnoDB; ...它没有显示在information_schema.TABLE_CONSTRAINTS或我能发现的任何其他地方,所以我的印象是它只是默默地丢弃了。 您看到的名称可 ...
  • sp_rename将正常工作,不应该破坏任何东西,除非您在查询提示中的某个地方引用了当前名称。 sp_rename will work fine and shouldn't break anything unless you have queries somewhere that reference the current name(s) in a query hint.
  • 它就是MySQL如何在Windows上运行: http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_lower_case_table_names 的lower_case_table_names 如果设置为0,则表名称按指定存储,并且比较区分大小写。 如果设置为1,则表名称以小写形式存储在磁盘上,并且比较不区分大小写。 如果设置为2,则表名存储为给定但以小写形式进行比较。 此选项也适用于数据库名称和表别名。 有关其 ...
  • SQLite的ALTER TABLE不支持此功能。 只需重新创建它: DROP INDEX old_index; CREATE INDEX new_index ON demo([...]); 您可以从架构中获取索引定义: SELECT sql FROM sqlite_master WHERE type = 'index' AND name = 'old_index'; 但是没有机制可以从SQLite内部修改和执行结果。 SQLite's ALTER TABLE does not support this ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。