Azure Cosmos SQL API - 如何将自定义对象存储为 @PartitionKey

Azure Cosmos SQL API - How do I store a custom object as @PartitionKey

是否可以使用 Java 8. 使用 @PartitionKey 将自定义 POJO 存储为 Json 字符串?是的,请告诉我如何。

import com.azure.spring.data.cosmos.core.mapping.PartitionKey;

    @PartitionKey
        private Result result;

结果将具有类似 {"resultID":"1","secret":"my secret"}

的值

正如@Mark Brown 正确评论的那样,我认为 - “在 Cosmos DB 中无法将对象指定为分区键”,但是我做了一个嵌套的分区键路径,如下所示:

import com.azure.spring.data.cosmos.core.mapping.Container;

    @Container(containerName = "DcLogins", partitionKeyPath = "/result/company",autoScale = true)
    public class DcLogins {
     private Result result;
 
    public class Result {
     private String company;

只是提一下,在 partitionKeyPath 中,resultResult 的对象,并且 company 变量应该与您处理的 json 对象匹配{"company":"sapcustid","secret":"my secret"}