Play Framework Anorm& DB未解决 [英] Play Framework Anorm & DB Not Reseolved

查看:194
本文介绍了Play Framework Anorm& DB未解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用Play Framework 2.2.3,我在导入anorm._和api.db.DB方面遇到了很多麻烦,所以我可以设置我的SQL数据库。

I'm using the Play Framework 2.2.3 for my first time and I'm having a lot of trouble importing anorm._ and api.db.DB so I can set up my SQL databases.

我的设置如下:

MainController.scala

MainController.scala

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

object MainController extends Controller {...}

application.conf

application.conf

# db.default.driver=com.mysql.jdbc.Driver
# db.default.url="jdbc:mysql:/usr/local/path/to/database"

build.sbt

build.sbt

libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.27"

我的第一个问题是我是否正确设置了MySQL数据库连接。另一件事是,当我尝试使用IntelliJ找到导入时,它发现它很棒。但是当我在浏览器中编译时,我收到编译错误:对象db不是包play.api的成员。有小费吗?

My first question is whether or not I'm setting up MySQL database connection correctly. The other thing is that when I try to find the import with my IntelliJ, it finds it great. But when I compile in my browser, I get a compilation error: object db is not a member of package play.api. Any tips?

我同时下载了Play 2.2.2和2.2.3,并且两者都遇到了这个问题,因此排除了版本问题。我从网站安装,我将文件解压缩到我的主文件夹,并使用

I downloaded both Play 2.2.2 and 2.2.3, and with both I had this problem so version problems are ruled out. I installed from the website, I unzipped the file into my Home folder, and used

play new app
cd app/
play
idea with-sources=yes

老实说,我不知道发生了什么。

for my installation. I honestly just have no idea what's going on.

推荐答案

只需将此添加到您的依赖项中

simply add this to your dependency

 <dependency>
    <groupId>com.typesafe.play</groupId>
    <artifactId>play-jdbc_2.11</artifactId>
    <version>2.4.6</version>
</dependency>

这篇关于Play Framework Anorm&amp; DB未解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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