开发者

Java controllers in Scala project in play framework?

Is it possible to have both java and scala controllers and views in play framework project when the project is 开发者_Python百科created with scala option?


Yes, it's possible to mix Java and Scala in a Play application. You can mix both Java and Scala controllers and Groovy and Scala templates. The instructions below have been tested with Play! 1.2.2RC1.

I would start by keeping both your Java and Scala controllers in app/controllers. Java is of course limited to one class per file, but in Scala packages are not tied to files and directories, so you can give your Scala file any name; as long as you declare the package correctly as

package controllers

Play should have not trouble finding them.

Scala templates should end in .scala.html and Groovy templates in plain .html. In a Scala controller, you render Scala templates with html.templatename and Groovy templates with Template("templatename").

I have never tried rendering a Scala template from a Java controller, but I don't see why it should not be feasible.

Finally, here's a useful reminder on Scala/Java interop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜