从游戏框架中的控制台访问模型 [英] Access Models from console in play framework

查看:49
本文介绍了从游戏框架中的控制台访问模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Play Framework 中的控制台访问模型?

How to access models from console in Play Framework?

我在尝试获取用户时遇到此错误.

I get this error when trying to fetch a user.

scala> import models._
import models._

scala> User.find.byId(1)
java.lang.RuntimeException: There is no started application

推荐答案

进入控制台时没有应用程序运行,所以没有为数据库等保留连接池

When entering the console there is no application running, so there is no connection pool kept for the database, etc.

您可以使用 StaticApplication 来解决这个问题.

You can use a StaticApplication to solve this.

scala> import play.core.StaticApplication
scala> import java.io.File
scala> val app = new StaticApplication(new File("."))

创建 StaticApplication 将自动启动它.完成后:

Creating the StaticApplication will automatically start it. And when you're done:

scala> play.api.Play.stop

这篇关于从游戏框架中的控制台访问模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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