简体   繁体   English

带有Anorm的Scala Play 2.3.0-无法使用模式匹配(IntelliJ无法解析符号行)

[英]Scala Play 2.3.0 with Anorm - Can't use Pattern Matching (IntelliJ cannot resolve symbol Row)

I am developing an application with Scala (2.11) and Play Framework (2.3.0) on IntelliJ IDEA. 我正在IntelliJ IDEA上使用Scala(2.11)和Play Framework(2.3.0)开发应用程序。 I'm using Anorm to retrieve data from my database (MySQL with MariaDB). 我正在使用Anorm从我的数据库(带有MariaDB的MySQL)中检索数据。

Here is my first test application (it works): 这是我的第一个测试应用程序(可以运行):

package controllers

import play.api.mvc._
import play.api.db._
import anorm._

case class Client(id: Int, nom: String, prenom: String)

object Application extends Controller {

  def index = Action {
    var result: List[(Int, String)] = List()
    val sqlQuery = SQL(
      """
        select idClient, nameClient from Clients
        where idClient = {idClient};
      """
    ).on("idClient" -> 1)

    DB.withConnection { implicit conn =>
      result = sqlQuery().map(row =>
        row[Int]("IDClient") -> row[String]("NameClient")
      ).toList

    }
    Ok(result.toString)
  }
}

This works fine. 这很好。 I get the name of my client correctly. 我正确获得了客户的名字。 However, when I try to use pattern matching, like this: 但是,当我尝试使用模式匹配时,如下所示:

result = sqlQuery().collect {
  case Row(idClient: Int, nameClient: String) => idClient -> nameClient
}

IntelliJ gives me an error, stating that it " Cannot resolve Symbol Row ". IntelliJ给我一个错误,指出它“ Cannot resolve Symbol Row ”。 As far as I know, Row is defined in the Anorm library, and so is SQL. 据我所知,Row是在Anorm库中定义的,SQL也是如此。 It doesn't make sense that SQL would be found and not Row... 将找不到SQL而不是Row是没有道理的...

What's happening? 发生了什么?

anorm.Row extractor is not there in Play 2.3 . anorm.Play 2.3中没有行提取器。 As suggested you could use parser. 如建议的那样,您可以使用解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM