如何将scala.js与mySQL数据库连接?
如何使用mySQL数据库连接Scala.js控制器方法 这就是我到目前为止所做的: 案例类datauser\u d:String,udid:String,image:String 对象mysqlDAO{ def findByIdudid:Long:选项[数据]={ val connection=DriverManager.getConnectionjdbc:mysql://localhost:3307/umo根 试一试{ val语句=connection.prepareStatementselect*从udid=? statement.setLong1,udid val rs=语句.executeQuery 如果是下一个 选项新建数据rs.getString1、rs.getString2、rs.getString3 其他的 选项1.empty }最后{ 连接。关闭 } } }如何将scala.js与mySQL数据库连接?,mysql,scala.js,Mysql,Scala.js,如何使用mySQL数据库连接Scala.js控制器方法 这就是我到目前为止所做的: 案例类datauser\u d:String,udid:String,image:String 对象mysqlDAO{ def findByIdudid:Long:选项[数据]={ val connection=DriverManager.getConnectionjdbc:mysql://localhost:3307/umo根 试一试{ val语句=connection.prepareStatementsele
first of all you can create the case class in Model package then u can create object and serialize the your case class Data
----------
case class Data(user_id: String, id: String, image: String)
object Data {
/* this one is the serialization of the data*/
implicit val DataWrites = new Writes[Data] {
def writes(json_write: Data): JsValue = {
Json.obj(
"user_id" -> json_write.user_id,
"id" -> json_write.id,
"image" -> json_write.image
)
}
}
val simple = {
get[String]("user.user_id") ~
get[String]("user.id") ~
get[String]("user.image") map {
case user_id ~ id ~ image =>
Data(user_id, id, image)
}
}
/*to get the data */
def find(udid: String): Option[Data] = {
DB.withConnection { implicit connection =>
SQL(ConstantSQL.GET_DETAILS).on('uid -> id).as(Data.simple.singleOpt)
}
}
}
----------
//query for to get the data based on the uid
val GET_DETAILS = """select * from user_image where uid = ?"""
then u can create your own controller method
----------
var uDetails = Data.find(uid)
----------
use the above line to get the data in your class