将实体字段在从Spring Rest发送到UI之前进行脱敏处理。

huangapple go评论72阅读模式
英文:

Mask entity field before sending to UI from Spring Rest

问题

我们正在使用Spring Rest,该接口将课程实体对象返回给用户界面。用户界面会修改课程对象并更新它。在这里,我们不希望向修改课程对象的用户显示URL字段。因此,我想对该字段进行屏蔽处理。请问您可以提供修改的最佳方法吗?

英文:

we are using spring rest which returns course entity object to UI. UI modify course object and update course object. here we don't want to show the URL field to a user who is modifying that course object. so I want to mask that single field. can you please suggest the best way to modify that

答案1

得分: 1

  • 从数据库中只获取相关数据 - 查看Spring Data REST的Projection功能。它允许获取实体数据的子集并自动公开它。

  • 抑制实体数据序列化 - 如果您需要获取实体数据但从不公开它,可以在字段上使用简单的@JsonIgnore注解。

英文:
  • Bring only relevant data from database - Check Spring Data REST Projection facility. It allows bringing a subset of entity data and automatically expose it.

  • Suppress entity data serialization - If you need to bring entity data but never expose it, a simple @JsonIgnore annotation on field may be used.

答案2

得分: 0

最终,我们实施了这个方案。与其进行掩盖,我们决定不通过 @JsonIgnore 将该字段发送到 UI。但是在更新对象时出现了问题。所以只对 getter 方法添加了 @jsonIgnore,然后对该字段添加了 @JsonProperty(access = Access.WRITE_ONLY)。因此,与其掩盖,我们选择不向 UI 发送该字段,并允许通过 @jsonIgnore 的定制来进行写入。

英文:

Eventually, we implemented this. instead of masking, we decided don't want to send that field to UI by @JsonIgnore. But that failed while updating the object. so added @jsonIgnore only got getter method and add @JsonProperty(access = Access.WRITE_ONLY) to the field. so instead of masking we are not sending the field to UI and allow the field to write by customization of @jsonIgnore

huangapple
  • 本文由 发表于 2020年10月22日 01:55:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/64469151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定