带有Anorm的Scala Play 2.3.0-无法使用模式匹配(IntelliJ无法解析符号行) [英] Scala Play 2.3.0 with Anorm - Can't use Pattern Matching (IntelliJ cannot resolve symbol Row)

查看:89
本文介绍了带有Anorm的Scala Play 2.3.0-无法使用模式匹配(IntelliJ无法解析符号行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在IntelliJ IDEA上使用Scala(2.11)和Play Framework(2.3.0)开发应用程序.我正在使用Anorm从我的数据库(带有MariaDB的MySQL)中检索数据.

I am developing an application with Scala (2.11) and Play Framework (2.3.0) on IntelliJ IDEA. I'm using Anorm to retrieve data from my database (MySQL with MariaDB).

这是我的第一个测试应用程序(可以运行):

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给我一个错误,指出它为"Cannot resolve Symbol Row".据我所知,Row是在Anorm库中定义的,SQL也是如此.将不会找到SQL而不是Row ...

IntelliJ gives me an error, stating that it "Cannot resolve Symbol Row". As far as I know, Row is defined in the Anorm library, and so is SQL. It doesn't make sense that SQL would be found and not Row...

发生了什么事?

推荐答案

anorm.Row提取器在Play 2.3中不存在.如建议的那样,您可以使用解析器.

anorm.Row extractor is not there in Play 2.3 . As suggested you could use parser.

这篇关于带有Anorm的Scala Play 2.3.0-无法使用模式匹配(IntelliJ无法解析符号行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆