14. JSON respond
—
install(ContentNegotiation) {
jackson {
}
}
get("/api/v1/books") {
val book = BookRespond("...")
call.respond(
mapOf("book" to book)
)
}
data class BookRespond (
val title: String,
val isbn: String,
)
17. —
object Books : Table() {
val id: Column<Int> = integer("id")
.autoIncrement()
.primaryKey()
val title: Column<String> = varchar("title", 255)
val isbn: Column<String> = varchar("isbn", 13)
val publishedAt: Column<DateTime> = datetime("...")
}
object Books : IntIdTable() {
val title = varchar("title", 255)
val isbn = varchar("isbn", 13)
val publishedAt = datetime("...")
}
18. DAO
—
class Book(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Book>(Books)
var title by Books.title
var isbn by Books.isbn
var publishedAt by Books.publishedAt
}