amazon-dynamodb - 如何根据项目的其他属性值在 DynamoDBMapper 中自动生成属性
问题描述
假设一个学生表具有以下属性 id、course_code、joining_year、admission_number。学生 ID 是根据此模式的其他属性 {course_code}_{joining_year}_{admission_number} 自动生成的。这可以使用 AWS DynamoDBMapper @DynamoDBAutoGenerated 来完成吗?如果有怎么办?还是有其他方法可以做到这一点?
解决方案
它无法完成,因为自动生成器 api 不允许您自省 POJO 中的任何其他字段。但是,您可以通过getStudentId()
使用 POJO 中的其他字段计算值来获得所需的结果。
例如:
String getStudentId() {
if (this.studentId == null) {
this.studentId = String.format("%s_%s_%s", this.courseCode, this.joiningYear, this.admissionNumber);
}
return this.studentId;
}
推荐阅读
- android - 有没有办法让 ListView 滚动表现得像 iOS 中一样?
- php - 我如何分离一个功能,并将其调用给我的所有控制器
- r - R生成十分位数
- python - Python更改等于对象?
- javascript - function[(thisArg)]) 语法是什么意思?
- r - 具有多个分类值的 ggplot 时间序列的最佳方法
- node.js - 如何在没有任何 json 文件的情况下使用 Firebase Auth 进行身份验证?
- c# - DataTable 的排序箭头未出现(在浏览器中显示 404)
- php - Laravel 中间件 - 跳过 Passport Auth
- javascript - Drive Batch API 返回文本内容以及可解析的 json 内容