在 Scala 中找不到值 ~

not found value ~ in Scala

我正在定义一些路径,但后来我 运行 进入这个错误,因为波浪号 ~ 就在“ pathPrefix(start)” 之前。我对 Scala 有点陌生,所以有些东西不会马上点击​​。谢谢

 not found:value ~ 

是不是因为我需要定义一个函数?如果是,为什么?

import   
  akka.http.scaladsl.marshallers.xml.ScalaXmlSupport.defaultNodeSeqMarshaller
    import akka.http.scaladsl.server.{ HttpApp, Route }
    import akka.http.scaladsl.model.StatusCodes
    import akka.actor.ActorSystem
    import akka.stream.ActorMaterializer
    import com.typesafe.config.ConfigFactory
    import akka.event.Logging
    import akka.http.scaladsl.model._


    object ABC extends HttpApp with App {

          implicit val actorSystem = ActorSystem()
          implicit val matter = ActorMaterializer()                                                               
          val start = "hello"

        val Routing= {

            path(start) {
              redirect( Uri(start+ "/index.html"), StatusCodes.PermanentRedirect )
              } 
              ~
              pathPrefix(start) {         
                 content  

                }
            } 

val content = 
{ 
 get 
   {
    path("html") {
                 getFromResource("src/html") }
  }
}

}

确保您有以下导入:

import akka.http.scaladsl.server.Directives._

根据@chunjef 的回答添加导入后,还要注意 ~ 是一个 infix operator,因此它附带了它的所有 "quirks"。 要整理您的路线,您可以避免将 ~ 换行

    val Routing= {

        path(start) {
          redirect( Uri(start+ "/index.html"), StatusCodes.PermanentRedirect )
          } ~
          pathPrefix(start) {         
             content  

            }
        } 

或者您可以将串联的路由括在括号中

   val Routing= {

        (path(start) {
          redirect( Uri(start+ "/index.html"), StatusCodes.PermanentRedirect )
          } 
          ~
          pathPrefix(start) {         
             content  

            })
        }