有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在Dynamo DB中更新保留关键字的值。错误:属性名称是保留关键字;保留关键字:数据

这是我正在操作的更新查询。这里的错误是“set data=:updateValue”,数据是来自Dynamo DB的保留关键字。我想我应该在这里使用updateexpressionattributes,但不确定如何在这种情况下使用

UpdateItemSpec updatetable = new UpdateItemSpec()
                .withPrimaryKey("pId", jsonContext.read("$.pId"))
                .withUpdateExpression("set data = :updateValue")
                .withValueMap(new ValueMap().with(":updateValue", jsonpathCreatorLocation2));
    locTable2.updateItem(updatetable);

共 (1) 个答案

  1. # 1 楼答案

    final Map<String, String> expressions = new HashMap<>();
    expressions.put("#d", "data");
    
    UpdateItemSpec updatetable = new UpdateItemSpec()
                    .withPrimaryKey("pId", jsonContext.read("$.pId"))
                    .withUpdateExpression("set #d = :updateValue")
                    .withValueMap(new ValueMap().with(":updateValue", jsonpathCreatorLocation2));
                    .withExpressionAttributeNames(expressions);
    
    locTable2.updateItem(updatetable);