简体   繁体   English

DyanmoDb 正在存储值 1 而不是布尔值 true

[英]DyanmoDb is storing value 1 instead of boolean value true

I have a method which is simply storing flag value true for a particular record.我有一个方法,它只是为特定记录存储标志值 true。 My flag attribute has been defined as Boolean which has value true/false in my DynamoDB database.我的标志属性已被定义为布尔值,在我的 DynamoDB 数据库中它的值为 true/false。 While running this method, somehow instead of storing true value, it is inserting a new column for the flag attribute as number datatype and writing value 1 instead of true.在运行此方法时,它以某种方式为标志属性插入一个新列作为数字数据类型并写入值 1 而不是真值,而不是存储真值。 While debugging I can see it is reading the value as "true" but while writing my guess is it is taking 1 for true and 0 for false, and hence writing 1.在调试时,我可以看到它正在将值读取为“true”,但是在编写我的猜测时,它以 1 为真,为 0 为假,因此写为 1。

public static ArrayList<UserWishListBuks> removeNotification(int Statusid) {
    AmazonDynamoDBClient ddb = NavigationDrawerActivity.clientManager
            .ddb();
    DynamoDBMapper mapper = new DynamoDBMapper(ddb);
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    Boolean value = true;
    try{
        PaginatedScanList<UserWishListBuks> result = mapper.scan(
                UserWishListBuks.class, scanExpression);
        for (UserWishListBuks bre : result) {
            if( (bre.getBOOK_STATUS_ID()==(Statusid))   )
            {
                bre.setNOTIFICATION_FLAG(true);
                mapper.save(bre);
            }
        }
    }catch (AmazonServiceException ex) {
        NavigationDrawerActivity.clientManager
                .wipeCredentialsOnAuthError(ex);
    }
    return null;
   }

DynamoDb will store the boolean value as 0 or 1 by default.默认情况下,DynamoDb 会将布尔值存储为 0 或 1。

Use the following decorators to save the attribute as false or true respectively.使用以下装饰器分别将属性保存为falsetrue

@DynamoDBTyped(DynamoDBAttributeType.BOOL)
@DynamoDBAttribute
private boolean notificationFlag;

Note: @DynamoDBNativeBoolean which used to do this is deprecated注意:用于执行此操作的@DynamoDBNativeBoolean 已弃用

That's expected, have a look at the datatypes docs for dynamodb: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.DataTypes.html这是预期的,看看 dynamodb 的数据类型文档: http ://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.DataTypes.html

The Java type of Boolean will be stored as a number type in dynamodb, 0 or 1. Alternatively, you can use @DynamoDBNativeBooleanType to map a Java Boolean to the DynamoDB BOOL data type Java 类型的布尔值将作为数字类型存储在 dynamodb 中,0 或 1。或者,您可以使用@DynamoDBNativeBooleanType将 Java Boolean映射到 DynamoDB BOOL数据类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM