Appengine ID /名称与WebSafeKey [英] Appengine ID/Name vs WebSafeKey

查看:127
本文介绍了Appengine ID /名称与WebSafeKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java中编写端点时,如果要按键查找项目,我应该使用键的 Id 还是 webSafeString ?在这种情况下,这很重要吗?

解决方案

这取决于你。




  • 实体是否有父母?那么你可能希望使用 urlsafe 表示法,因为单个字符串将包含实体的完整路径。如果您使用的是ID,则您需要手动将所有父母的ID包含在根目录中。

  • 没有父母& ID是数字/字母数字?然后只需使用这些ID,因为它们看起来更干净(再次,这不是一个规则,完全取决于你)。
  • 没有父母,但ID有特殊字符在他们中?使用 urlsafe 表示法,因为您可能会遇到无法使用某些特殊字符而无法在HTTP中进行编码的问题。


    <注意#1: urlsafe 表示具有编码的实体名称,可以很容易解码,这不太可能是隐私问题,但您仍然应该知道它。实际数据(ID)也是简单编码的,并且可以很容易解码,所以当您使用个人信息(如电子邮件)作为ID时,请小心谨慎,使用 urlsafe 不安全。注意#2:如果您决定在未来更改数据结构(父母< - >儿童),您可能会遇到一些 urlsafe 您发布给用户的数据,这些用户不知道您可能已经完成的更改。 $ b

    When writing the endpoints in java, for finding items by their keys, should I use the Id or the webSafeString of the key? In what situations does this matter?

    解决方案

    It's up to you.

    • Do the entities have parents? Then you probably want to use the urlsafe representation as a single string will contain the full path to the entity. If you used an ID instead - you would somehow need to manually include the IDs of all parents up to the root.

    • No parents & IDs are numeric / alphanumeric? Then just use the IDs as they look cleaner (again, this is not a rule and is completely up to you).

    • No parents but IDs have special characters in them? Use the urlsafe representation as you might have issues with not being able to use some special characters without encoding them in HTTP.

    • Note #1: the urlsafe representation have the entity names encoded that can be easily decoded, this is unlikely a privacy issue but you still should be aware of it. The actual data (IDs) are also simply encoded and can be easily decoded, so be careful when you use personal information such as emails as IDs, they are not safe with urlsafe.

    • Note #2: if you decide to change the structure of your data in the future (parents <-> children), you might get stuck with some urlsafe data you issued to your users who are not aware of the changes you might have done.

    这篇关于Appengine ID /名称与WebSafeKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆