Java controllers in Scala project in game?

Is it possible to have both java and scala controllers and views in a framework project when creating a project using the scala option?

+6
source share
1 answer

Yes, it is 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 on Play! 1.2.2RC1.

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

 package controllers 

Play should not have found them.

Scala templates should end with .scala.html and Groovy templates in regular .html . In the Scala controller, you create Scala templates with the html.templatename and Groovy templates with the Template("templatename").

I have never tried displaying a Scala pattern from a Java controller, but I do not understand why this should not be possible.

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

+4
source

Source: https://habr.com/ru/post/890737/


All Articles