_class字段和spring数据基础 [英] _class field and spring data couchbase

查看:100
本文介绍了_class字段和spring数据基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正试图找到一种方法,以从Spring Data Couchbase生成的文档中删除/重命名(并更改field值)_class字段,因为该文档将由一个服务存储,并且很可能是被完全不同的人食用.

So, I was trying to find a way to remove/rename( and change the fields value ) the _class field from the document generated by spring data couchbase as the document is going to be stored by one service and in all likeliness be consumed by someone totally different.

我在玩Spring沙发床的api,并经过反复试验发现,我可以使用以下方式使用自定义值重命名_class字段->

I was playing around with the api for spring couchbase and through a bit of trial and error found that I can rename the _class field with a custom value using the following way ->

1)在继承AbstractCouchbaseConfiguration的类中重写typeKey方法.例如,假设我们重写了typeKey以执行以下操作->

1) Override the typeKey method in a class inheriting AbstractCouchbaseConfiguration . For example, let's say we overrided typeKey to do the following ->

@Override public String typeKey() { return "type"; }

@Override public String typeKey() { return "type"; }

2)在将数据存储到榻榻米数据库的POJO中,将与您输入的字段名称相同的字段添加到typeKey方法的返回值中,并根据需要为其提供自定义值-

2) In the POJO that stores the data into couchbase, add a field with the same field name as what you gave into the return value of the typeKey method and give it the custom value as needed -

private final String type = "studentDoc";

我想检查一下这是否是一种有效的方法,或者/并且现在有一些更好的方法可以用来做这样的事情

I wanted to check if this is a valid way of going about this or/and some better way is available to do something like this now

推荐答案

这是目前使用spring数据的唯一方法,我们想添加一些额外的方法来做到这一点,但仅限于Spring Data接口协定.这就是为什么大多数额外的配置都是通过AbstractCouchbaseConfiguration完成的原因.

That is the only way to do it with spring data at this moment, we would like to add a few extra ways to do that but we are limited to the Spring Data interface contracts. That is why most of the extra configs are done via AbstractCouchbaseConfiguration.

这篇关于_class字段和spring数据基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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