project/build.sbt以下是scalatra/spark 项目的核心:
val ScalaVersion = "2.11.6"
val ScalatraVersion = "2.4.0-RC2-2"
// ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true)}
lazy val project = Project (
"keywordsservlet",
file("."),
settings = ScalatraPlugin.scalatraSettings ++ scalateSettings ++ Seq(
organization := Organization,
name := Name,
version := Version,
scalaVersion := ScalaVersion,
resolvers += Classpaths.typesafeReleases,
resolvers += "Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases",
libraryDependencies ++= Seq(
// "org.scala-lang" % "scala-reflect" % ScalaVersion,
"org.apache.spark" % "spark-core_2.11" % "1.4.1",
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % …Run Code Online (Sandbox Code Playgroud) 我有一个跟随我最近问的另一个Slick问题(Slick table Query:Trouble with recognition value).请多多包涵!!我是数据库的新手,Slick在文档方面似乎特别差.无论如何,我有这张桌子:
object Users extends Table[(Int, String)]("Users") {
def userId = column[Int]("UserId", O.PrimaryKey, O.AutoInc)
def userName = column[String]("UserName")
def * = userId ~ userName
}
Run Code Online (Sandbox Code Playgroud)
第一部分
我正在尝试使用此函数进行查询:
def findByQuery(where: List[(String, String)]) = SlickInit.dbSlave withSession {
val q = for {
x <- Users if foo((x.userId, x.userName), where)
} yield x
q.firstOption.map { case(userId, userName) =>
User(userId, userName)}
}
Run Code Online (Sandbox Code Playgroud)
其中"where"是搜索查询列表// ex.("userId","1"),("userName","Alex")"foo"是测试相等性的辅助函数.我遇到了类型错误.
x.userId的类型为Column [Int].如何将其作为Int来操纵?我试过铸造,例如:
foo(x.userId.asInstanceOf[Int]...)
Run Code Online (Sandbox Code Playgroud)
但我也遇到了麻烦.如何处理Slick返回类型?
第二部分 是否有人熟悉铸造功能:
def*= userId~userName <>(User,User.unapply _)
?我知道这个问题有一些很好的答案,最值得一提的是:到目前为止我无法理解的scala光滑方法和一个非常相似的问题:在SLICK中用伴随对象映射投影 …
我正在使用scalatra,并将servlet配置为始终返回JSON(如相应指南中所述)。使用MongoDB和Salat使我回到将MongoDBObject读回到我的case类中的地步-这似乎很棒。
我的案例课:
import org.bson.types.ObjectId
import com.novus.salat.annotations.raw.Key
case class Player(_id: ObjectId, firstName: String, ...)
Run Code Online (Sandbox Code Playgroud)
打印case类对象将输出以下内容:
Player(547489ee93f4272e548ded63,Peter,...)
Run Code Online (Sandbox Code Playgroud)
如您所见,objectid是org.bson.types.ObjectId。自动序列化为JSON会将其发送到浏览器:
{"_id":{},"firstName":"Peter",...}
Run Code Online (Sandbox Code Playgroud)
我的ObjectID在哪里?我究竟做错了什么?
scalatra(Scala服务器端框架)是否在我们的一个源代码发生变化时自动刷新(就像PHP一样)?
或者如果它们不是,是否有任何Scala服务器端框架能够做到这一点(编辑代码,然后在浏览器上测试,而无需重新启动scala/server程序)?