corda - 如何在corda的默认构造函数中设置日期和金额(货币)的值
问题描述
如何在corda程序中为日期和金额(货币)字段默认构造函数(在模式中)设置值。我尝试评论构造函数,但在 API 中遇到错误。
解决方案
这是一个模式,其中一个字段具有默认值value
:
object IOUSchemaV1 : MappedSchema(
schemaFamily = IOUSchema.javaClass,
version = 1,
mappedTypes = listOf(PersistentIOU::class.java)) {
@Entity
@Table(name = "iou_states")
class PersistentIOU(
@Column(name = "lender")
var lenderName: String,
@Column(name = "borrower")
var borrowerName: String,
@Column(name = "linear_id")
var linearId: UUID,
@Column(name = "value")
var value: Int = 93
) : PersistentState() {
// Default constructor required by hibernate.
constructor(): this("", "", UUID.randomUUID(), 0)
}
}
如果您没有为此字段提供值,则将使用默认值93
。例如:
override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) {
is IOUSchemaV1 -> IOUSchemaV1.PersistentIOU(
this.lender.name.toString(),
this.borrower.name.toString(),
this.linearId.id
)
else -> throw IllegalArgumentException("Unrecognised schema $schema")
}
}
推荐阅读
- sql - 列出部门名称和每个部门的员工人数
- elasticsearch - 索引弹性搜索期间未显示结果
- pandas - 确定对数据进行分箱的最佳分箱
- clickhouse - 如何确定clickhouse的分区键
- xslt - xslt 用于将一个元素转换为多个元素中的属性
- opencv - 在使用 pytesseract/tesseract 从扭曲、模糊的图像中提取文本之前应用的预处理方法
- css - 尝试使用 Flexbox 垂直居中
- django - 生产机器上的 Celery 和 Django
- node.js - 如何在 Node.js 中解析证书吊销列表 (CRL)
- python - 为什么将数组转换为 Tensor 会增加维度?