2016-09-17 36 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

我會試一下。我很好奇你做了什麼。 –

相關問題