且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有List属性的REST资源

更新时间:2023-08-24 23:41:46

我认为,每次更改某项内容时,仅让客户端上载当前人的所有信息是最有意义的.但是,如果满足以下条件,这可能是不够的:

I'm thinking it'd make the most sense to simply have the client upload all the info for the current person every time something is changed. However, this might not be adequate if:

  • 在典型情况下,每次更改都必须来回发送大量数据.
  • 多个人可以同时编辑同一个人.

如果您的人员对象很大,则可以考虑采用差异/补丁方法.发送新版本之前,请将其与旧版本进行比较.如果单身人士栏位(例如firstName)发生变更,只需在JSON物件中列出即可:

If your people objects are large, you might consider taking a diff/patch approach. Before sending the new version, compare it to the old version. If a singleton field (e.g. firstName) changed, simply list it in your JSON object:

{
 "firstName":"New first name"
}

对于电话号码数组,请按键列出要删除的电话号码,然后像通常一样列出要添加的新电话号码.像这样:

For the array of phone numbers, list the phone numbers to remove by key, and list the new phone numbers to add like you normally would. Something like this:

{
 "+phoneNumbers":[
  {"key":"123456789abc","number":"555-123-4567"}
 ],
 "-phoneNumbers":[
  "49fnfnsa0sas"
 ]
}

您还可以Google搜索"json diff",看看您发现的任何结果是否有帮助.

You could also Google search "json diff" and see if any of the results you find are helpful.

正如我之前所说,除非您有充分的理由要介绍这种复杂的深度,否则***让客户端重新上传整个person对象以进行更新.

As I said before, unless you have a compelling reason to go to this depth of complexity, it's probably best to just have the client re-upload the entire person object to update it.