【问题标题】:Kotlin Server Ktor Exposed: how to nullable optional FieldsKotlin Server Ktor Exposed:如何为可空的可选字段
【发布时间】:2021-12-27 17:02:24
【问题描述】:

我的 Ktor + Exposed App 上有这个功能。

override suspend fun createNewCourse(course: CourseModel): Flow<CourseModel> {
    transaction {
        CoursesTable.insert {
            it[requiredCourseId] = course.requiredCourse?.id!!
            it[category] = course.category?.id!!
            it[isPopular] = course.isPopular == true
            it[position] =  course.position
            it[nameEN] = course.name.en
            it[warningEN] = course.warning.en
        }
    }

它无法编译。 有时某些变量(如“warningEN”)可能为空,我不想为此字段插入任何内容。

如何制作?

类型不匹配。 必需:TypeVariable(S) 找到:字符串?

【问题讨论】:

    标签: kotlin server ktor kotlin-exposed


    【解决方案1】:

    我的解决方案:

    it[position] =  course.position?.let { course.position!! } ?: null
    

    【讨论】:

      猜你喜欢
      • 2022-07-06
      • 2017-04-04
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      相关资源
      最近更新 更多