import akka.actor.Actor
import spray.routing.HttpService
import spray.http._
import MediaTypes._
import spray.json._
import spray.routing.directives.CachingDirectives._
import spray.httpx.encoding._
trait MarginEvaluationService extends HttpService {
import ClassSerializer._
import spray.httpx.SprayJsonSupport._
val myRoute = {
pathPrefix("hello") {
get {
respondWithMediaType(`text/html`) { // XML is marshalled to `text/xml` by default, so we simply override here
complete {
<html>
<body>
<h1>Say hello to <i>spray-routing</i> on <i>spray-can</i>!</h1>
</body>
</html>
}
}
}
}
~
pathPrefix("testjson") {
get {
entity(as[TestC]) { c =>
respondWithMediaType(`application/json`) {
complete(c)
}
}
}
}
}
}
route被窃听:
Error:(49, 1) illegal start of simple expression pathPrefix("testjson") { ^
path
有什么区别和 pathPrefix
?我不确定
~
运算符未正确包括在内。
最佳答案
在 docs :
路径(x) : 等价于 rawPathPrefix(slash().concat(segment(x)).concat(pathEnd()))。它匹配前导斜杠,后跟 x 和结尾。
路径前缀(x) : 等价于 rawPathPrefix(slash().concat(segment(x)))。它匹配前导斜杠后跟 x,然后留下不匹配的后缀。
关于scala - 喷:路由——了解path和pathPrefix的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31858814/