【发布时间】:2018-11-22 10:10:55
【问题描述】:
帮帮我,我想从数据库中查询数据并保存为json格式,然后响应客户端。
implicit val locationWrites1: Writes[Location] = (
(JsPath \ "id").write[String] and
(JsPath \ "desc").write[String]
) (unlift(Location.unapply))
db.withConnection { conn =>
val stm = conn.createStatement()
val res = stm.executeQuery(
"""
SELECT notes_id,notes_desc FROM notes
"""
)
while (res.next()) {
Location(res.getString(1), (res.getString(2)))
}
}
val result = Json.toJson(locationWrites1)
Ok(result)
【问题讨论】:
-
问题出在哪里?
-
我无法从查询中检索数据。保存成json格式发送给客户端
标签: mysql scala rest playframework