0
我嘗試使用的用戶名在dynamodb表中查找用戶(用戶名+密碼),用戶ID(INT)是主鍵等等的GetItem工作:尋找項目,而無需使用主鍵
val user = Try(table.getItem("userid",2233))//this works
查找用戶(以驗證密碼)使用的用戶名但不工作,我已經試過這
我有一個同伴對象:
object Authentication {
@DynamoDBTable(tableName = "users")
case class User(username: String, passwordMd5: String)
...
}
並使用此嘗試掃描():
val scanExpression = new DynamoDBScanExpression()
scanExpression.addFilterCondition("username",
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS("some_username")))`
,但是這給了我以下錯誤:
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: Class class Authentication$User$ must be annotated with interface com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable
我需要做什麼來解決這個問題?
解決方案(重寫):
val client = new AmazonDynamoDBClient(new ProfileCredentialsProvider())
client.setRegion(Region.getRegion(Regions.XXX))
val dynamoDB = new DynamoDB(client)
val table = dynamoDB.getTable("users")
val index = table.getIndex("username-index")
val spec = new QuerySpec()
.withKeyConditionExpression("username = :v_username")
.withValueMap(new ValueMap()
.withString(":v_username", username))
val items = index.query(spec)
val iterator = items.iterator()
val user = Try(iterator.next())
美中不足的是使用index.query(SPEC)不table.query(SPEC)
我使用,這是對用戶名的索引嘗試,那工作,謝謝。 – FelixHJ