1

这里应该有一些简单的东西,虽然我完全想念它,因为我是 Scala 和 Play 的菜鸟。这是代码:

case class ExceptionInfo(ExceptionType: String, Message: String, StackTrace: Seq[String])

object ExceptionInfo
    {
      val excInfoParser = {
        get[String]("ExceptionInfo.ExceptionType") ~ 
        get[String]("Message") ~ 
        get[String]("ExceptionInfo.StackTrace") map {
          case ExceptionType ~ Message ~ StackTrace => ExceptionInfo(ExceptionType, Message, StackTrace.split("\r\n"))
        }
      }
    }

这不会编译,输出如下:

Description Resource            Path                Location                        Type
not found: value ExceptionType  Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value Message        Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value StackTrace     Application.scala   /testme/app/controllers line 40 Scala Problem
not found: value ExceptionType  Application.scala   /testme/app/controllers line 40 Scala Problem

提前致谢!

4

1 回答 1

2

当您以小写字母命名变量时应该可以工作:

case exceptionType ~ message ~ stackTrace => ExceptionInfo(exceptionType, message, stackTrace.split("\r\n"))

小写是区分要绑定的变量(您要查找的内容)与要匹配的常量的区别。有关更多信息,请参见此处此处

于 2013-04-11T18:49:54.577 回答