Play Framework Anorm&数据库未解析 [英] Play Framework Anorm & DB Not Resolved

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

问题描述

我第一次使用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查找导入时,它会发现它很棒.但是,当我在浏览器中进行编译时,出现编译错误:object db不是package.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;数据库未解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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