2
我似乎在web上的例子很多有光滑3配置如下油滑3我怎樣才能在應用程序文件的默認配置
slick.dbs.default.driver="slick_driver"
slick.dbs.default.db.driver="db_driver"
slick.dbs.default.db.url="URL_file
slick.dbs.default.db.user="user"
slick.dbs.default.db.password="password"
我的問題是你怎麼能連接到Scala的內控制器?我正在使用播放框架版本2.4.6。我已經試過這
def db: Database = Database.forDataSource(DB.getDataSource())
,但我得到一個錯誤
Error:(5, 17) Play 2 Compiler:
C:\Users\nemer\mycontroller\app\controllers\Application.scala:5:
object db is not a member of package play.api
import play.api.db.DB
^
我的控制器看起來像這樣
package controllers
import org.mindrot.jbcrypt.BCrypt
import play.api.db.DB
import play.api.libs.json.{Json, JsValue}
import play.api.mvc._
import slick.driver.PostgresDriver.api._
import scala.concurrent.duration._
import scala.concurrent.Await
import play.api.libs.concurrent.Execution.Implicits._
class Application extends Controller {
// I am trying to get the Slick config settings in here
def db: Database = Database.forDataSource(DB.getDataSource())
def mypage = Action {
val json: JsValue = Json.parse("""
{
"name" : "Watership Down",
"location" : {
"lat" : 51.235685,
"long" : -1.309197
},
"residents" : [ {
"name" : "Fiver",
"age" : 4,
"role" : null
}, {
"name" : "Bigwig",
"age" : 6,
"role" : "Owsla"
} ]
}
""")
Ok(json).as("text/json")
}
}