[英]Play framework scala query binding for java class
I've got a java enum class 我有一个Java枚举类
public enum MahEnum {
YUP, VALUES
}
and a scala query binding so that I can use that enum in routes 和scala查询绑定,以便我可以在路由中使用该枚举
object MahBindings {
implicit def enumBinding = new QueryStringBindable[MahEnum] {
def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, MahEnum]] = ???
def unbind(key: String, value: Status): String = ???
}
}
How do I get play to recognize the bindings and apply them? 我该如何发挥作用来识别绑定并应用它们? If the bound class were in scala I could put the object in the scope of the class, but I've got a java enum.
如果绑定的类在scala中,则可以将对象放在类的范围内,但是我有一个Java枚举。
Assuming your QueryStringBindable
is already defined, you can import the implicits into the routes file with an sbt key. 假设您的
QueryStringBindable
已经定义,则可以使用sbt键将隐式导入到路由文件中。 For Play 2.5.x and 2.4.x: 对于Play 2.5.x和2.4.x:
import play.sbt.routes.RoutesKeys
RoutesKeys.routesImport += "MahBindings._"
Play 2.3.x and prior: 播放2.3.x及更高版本:
PlayKeys.routesImport += "MahBindings._"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.