简体   繁体   English

删除JAX-RS Service jersey实现中的多个资源

[英]Deletion of multiple resources in JAX-RS Service jersey implementation

I am new to restful services and willing to get some ideas from the experts. 我是新来的宁静服务,并愿意从专家那里得到一些想法。

The application which will be accessing my service is having a datatable-grid (each row of the grid represents an Employee Object/Entity) where user can delete more than 1 records at a time(based on the number of checkbox selected by the user). 将访问我的服务的应用程序是具有datatable-griddatatable-grid每一行代表一个员工对象/实体),其中用户可以一次删除多于1个记录(基于用户选择的复选框的数量) 。 In such kind of a delete operating how will be the URL representation and how will the data be send to the service? 在这种类型的删除操作中,URL表示将如何以及如何将数据发送到服务?

My Idea 我的点子

Since the number of rows deleted by the differs (based on the number of checkbox selected by the user), hence I am opting for the query string and below will be the URL representation using which I can get the data in my service: 由于删除的行数不同(基于用户选择的复选框的数量),因此我选择查询字符串,下面将是URL表示,使用该URL表示我可以获取服务中的数据:

/deleteEmployees?id=1,2,3

ie a comma seperated values of the id's which will uniquely identify a record in the table. 即id的逗号分隔值,它将唯一地标识表中的记录。

Based on my Idea, I have a few questions: 根据我的想法,我有几个问题:

1) The query String mentioned above contains of comma-seperated values (ie Ids). 1)上面提到的查询字符串包含comma-seperated值(即Ids)。 Is it a valid URL where query strings will contain this kind of values? 它是一个有效的URL,查询字符串将包含这种值吗?

2) Is there any restrictions in defining the query strings of an URL (like the way I did using csv)? 2)定义URL的查询字符串是否有任何限制(就像我使用csv一样)?

3) Any other alternative of achieving the same in a better and efficient manner? 3)以更好和有效的方式实现同​​样的任何其他选择吗?

PS I am new on this and hence looking for different ideas from the experts and try to understand what is correct and what is not. PS我是新手,因此寻找专家的不同想法,并试图了解什么是正确的,什么是不正确的。

A comma separated list of Employee ids is a fine way to do it, but I wouldn't put it in a URL with an action in it, ie. 以逗号分隔的Employee ID列表是一种很好的方法,但是我不会把它放在带有动作的URL中,即。 /deleteEmployees?id=1,2,3 . /deleteEmployees?id=1,2,3 REST is more about identifying resources, rather than actions, in URLs. REST更多的是在URL中识别资源而不是动作。 I would either loop through each one of the employee ids to delete and send an HTTP DELETE request for each 我要遍历每个员工ID以删除并发送每个员工ID的HTTP DELETE请求

DELETE /employees/1 HTTP/1.1
DELETE /employees/2 HTTP/1.1
DELETE /employees/3 HTTP/1.1

Another alternative is to send one HTTP DELETE request to a URL like /employees , keeping the suggested REST identification of resources and using HTTP methods. 另一种方法是将一个HTTP DELETE请求发送到像/employees这样的URL,保留建议的REST资源标识并使用HTTP方法。 You would pass the list of ids in an HTTP header. 您可以在HTTP标头中传递ID列表。

DELETE /employees HTTP/1.1
Employees-To-Delete: 1,2,3

Take a look at this answer for character restrictions in URLs. 请查看此答案中的URL中的字符限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM