2016-09-17 91 views
0

Doc说@Field注释可用于重命名实体中的字段。那些从技术上来说不是实体本身的嵌套POJO的领域呢?考虑下面的假设例子。Spring Data Couchbase:如何从嵌套的POJO中重命名字段?

@Document 
public class Person { 
    @Id 
    private String ssn; 
    @Field 
    private String name; 
    @Field 
    private Address address; 

    static class Address { 
     // how to rename this field to line1? 
     private String street; 
    } 
} 
+0

你试过@Field(NAME =” line1“) – Koitoer

+0

不,因为我想知道重命名支持有多远。我可以在查询中使用重命名的字段吗? –

+1

我不认为我在开发过程中测试了这个用例,所以我不会把它作为答案,但它应该与内部类中字段的注释一起工作,并且派生查询应该使用Java名称并获取转换为N1QL中的别名 –

回答

1

具体回答你的问题,你可以在Address使用@Field("line1")street

我已经在我的项目是这样的,它工作正常(见descriptions

1级

@Document 
@JsonInclude(JsonInclude.Include.NON_NULL) 
public class HotelInfo { 
    @Field("hotel_type") @JsonProperty("hotel_type") 
    public String hotelType; 
    @Field @JsonProperty("images") 
    public List<Image> images = new ArrayList<Image>(); 
    @Field @JsonProperty("regions") 
    public List<String> regions = new ArrayList<String>(); 
    @Field @JsonProperty("themes") 
    public List<String> themes = new ArrayList<String>(); 
    @Field @JsonProperty("facilities") 
    public List<String> facilities; 
    @Field @JsonProperty("descriptions") 
    public Descriptions descriptions; 
} 

2级

@JsonInclude(JsonInclude.Include.NON_NULL) 
public class Descriptions { 
    @Field("hotel_information") @JsonProperty("hotel_information") 
    public String hotelInformation; 
} 
+0

对于由您编写或由存储库生成的重命名字段,您是否有任何疑问? –

+0

对不起,但是如果我去试试它,我会报告回来。另外你为什么不尝试一下,让我们知道。祝你好运。 – prettyvoid

+0

我会试一下。我很好奇你做了什么。 –