Tag: playframework 2.0

在Play Framework 2.0中路由重载函数

在Play中,当重载控制器方法时,那些单独的方法不能被多次路由,因为编译器不喜欢它。 有没有办法解决这个问题? 假设我的Product控制器中有两个函数: getBy(String name)和getBy(long id) 。 我在路由中声明了这些函数的两个不同routes : GET /p/:id controllers.Product.getBy(id: Long) GET /p/:name controllers.Product.getBy(name: String) 我想对不同的路线使用“相同”function,这可能吗?

Playframework – Eclipse无法检测到新模板

可能重复: 如何让Eclipse看到Play中的变化! 编译模板? 我正在玩Play的第一步! 框架和我遇到了一些问题。 我可以毫无问题地创建和超越项目。 现在,如果我添加一个新视图,例如’sometest.scala.html’,我尝试在’Application’中使用它,Eclipse会将此文件标记为错误。 package controllers; import play.*; import play.mvc.*; import views.html.*;; public class Application extends Controller { public static Result index() { return ok(sometest.render(“test”)); // this line is marked red } } Eclipse标记为红色,即使它有效。 如果我去localhost:9000,我可以看到我的变化。 我的视图文件夹如下所示: app –views —-index.scala.html —-main.scala.html —-sometest.scala.html 我创建了sometest作为html文件,并将文件名设置为.scala.html 简单解决方案 运行你的应用程序 $ cd myapp $ play $ run 转到你的webrwoser并输入:localhost:9000 […]

在运行时更改Guice绑定

我希望能够在运行时更改Guice注入,以支持基于用户输入的多次注入。 这就是我想要实现的目标: public interface IDao { public int someMethod(); } public class DaoEarth implements IDao { @Override public int someMethod(){ … } } public class DaoMars implements IDao { @Override public int someMethod(){ … } } public class MyClass { @Inject private IDao myDao; public int myMethod(String domain) { //If Domain == Earth, myDao should […]

如何在play框架中禁用http端口?

当我使用https端口运行Play Framework时,应用程序在两个端口上启动 – 默认(9000)和https(443)。 如何禁用默认9000端口并仅在https端口上运行播放应用程序? 我通过以下命令运行应用程序: play -Dhttps.port=443 -Dhttps.keyStore=/path/to/keystore -Dhttps.keyStorePassword=password start 我得到一些日志: [info] play – 应用程序启动(Prod) [info] play – 在/ 0上侦听HTTP:0:0:0:0:0:0:0:9000 [info] play – 在端口/ 0上侦听HTTPS:0:0:0:0:0:0:0:443

在Play 2.0 Framework模板引擎中进行计算

play 2.0模板引擎是否支持html页面中的简单计算。 让我们说,我创建了一个sum.scala.html页面: @(a:String, b: String) answer is getSum(@a,@b) 有什么方法可以通过某种function“获得a和b的sum”吗? 或者有任何游戏2.0专家对游戏2.0模板引擎中的计算有什么好主意吗? 谢谢

如何在Play Framework 2(Java)中有选择地禁用CSRF检查

在Play Framework中,我们可以应用全局CSRF检查 @SuppressWarnings({ “rawtypes”, “unchecked” }) @Override public Class[] filters() { Class[] filters = { CSRFFilter.class }; return filters; } 在大多数情况下都没问题。 但我想设置指向我们网站的Facebook Canvas页面。 事情是Facebook发送POST请求到我们的网站,它被CSRF检查阻止。 它总是返回“无效的CSRF令牌” 因此,我想在某些操作中有选择地禁用CSRF检查,例如www.ourwebsite.com/canvas 这可行吗?

为路由中的可选查询参数指定null默认值 – Play Framework

我正在尝试定义一个可选的查询参数,该参数将映射到Long ,但在URL中不存在时将为null : GET /foo controller.Foo.index(id: Long ?= null) ……我基本上想检查它是否传入: public static Result index(Long id) { if (id == null) {…} … } 但是,我收到了编译错误: 类型不匹配; found:Null(null)required:Long请注意,隐式转换不适用,因为它们不明确:类型为LowPriorityImplicits的类型为(x:Null)Long的方法和方法类型为(x:Long)Long的对象Predef中的Long2long方法可能的转换函数从Null(null)到Long 为什么我不能这样做,将null指定为预期的Long可选查询参数的默认值? 有什么替代方法可以做到这一点?

无法解析符号路径

IntelliJ IDEA 14中没有的“路线”有什么问题?

玩! framework 2.0:如何显示多个图像?

我需要显示一个照片库。 所以这是我的模板: @(photos: List[Photo]) @title = { Gallery } @main(title,”photo”){ @for(photo <- photos) { } } 这是我的控制器方法: public static Result getPhotos() { return ok(views.html.photo.gallery.render(Photo.get())); } 这是我的Photo bean: @Entity public class Photo extends Model { @Id public Long id; @Required public String label; public String path; public Photo(String path, String label) { this.path = path; this.label […]

如何在Play Framework中进行详细编译?

在使用Java的Play框架2.0.8中,是否可以进行详细的编译? 目前我只看到: [info]编译131个Scala源和10个Java源代码到…… 我正在尝试确定更改控制器时为什么会重新编译这么多文件的原因。 提前致谢