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

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

问题描述

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

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 给我一个错误,指出它无法解析符号行".据我所知,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.

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

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