作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Play 2.0.1 我定义了以下路线:
GET /demo/list controllers.Demos.listDemos(page: Int ?= 0, orderBy: Int ?= 1, nameFilter: String ?= "", versionFilter: Long ?= -1, tagFilter: List[String] ?= Nil)
No QueryString binder found for type List[String]. Try to implement an implicit QueryStringBindable for this type.
/**
* QueryString binder for List
*/
implicit def bindableList[T: QueryStringBindable] = new QueryStringBindable[List[T]] {
def bind(key: String, params: Map[String, Seq[String]]) = Some(Right(bindList[T](key, params)))
def unbind(key: String, values: List[T]) = unbindList(key, values)
}
/**
* QueryString binder for java.util.List
*/
implicit def bindableJavaList[T: QueryStringBindable] = new QueryStringBindable[java.util.List[T]] {
def bind(key: String, params: Map[String, Seq[String]]) = Some(Right(bindList[T](key, params).asJava))
def unbind(key: String, values: java.util.List[T]) = unbindList(key, values.asScala)
}
private def bindList[T: QueryStringBindable](key: String, params: Map[String, Seq[String]]): List[T] = {
for {
values <- params.get(key).toList
rawValue <- values
bound <- implicitly[QueryStringBindable[T]].bind(key, Map(key -> Seq(rawValue)))
value <- bound.right.toOption
} yield value
}
private def unbindList[T: QueryStringBindable](key: String, values: Iterable[T]): String = {
(for (value <- values) yield {
implicitly[QueryStringBindable[T]].unbind(key, value)
}).mkString("&")
}
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.slf4j#slf4j-api;1.6.1: configuration not found in org.slf4j#slf4j-api;1.6.1: 'compile'. It was required from org.hibernate#hibernate-validator;4.2.0.Final compile
[warn] :: commons-codec#commons-codec;1.4: configuration not found in commons-codec#commons-codec;1.4: 'compile'. It was required from org.apache.httpcomponents#httpclient;4.1.2 compile
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers ++= Seq(
Resolver.url("Typesafe Ivy Snapshots", url("http://repo.typesafe.com/typesafe/ivy-snapshots/"))(Resolver.ivyStylePatterns),
"Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/",
"Typesafe Snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
"DefaultMavenRepository" at "http://repo1.maven.org/maven2/",
"JavaNet1Repository" at "http://download.java.net/maven/1/")
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1-SNAPSHOT")
最佳答案
我终于解决了。使用的代码是:
下 型号 , 文件 QueryBinders.scala :
package models
import play.api.mvc.{JavascriptLitteral, QueryStringBindable}
/**
* Created with IntelliJ IDEA.
* User: pvillega
* Date: 07/05/12
* Time: 12:06
* QueryStringBinders for some data types missing in 2.0.1
*/
//TODO: remove when updating to 2.1
object QueryBinders {
/**
* QueryString binder for List
*/
implicit def bindableList[T: QueryStringBindable] = new QueryStringBindable[List[T]] {
def bind(key: String, params: Map[String, Seq[String]]) = Some(Right(bindList[T](key, params)))
def unbind(key: String, values: List[T]) = unbindList(key, values)
}
private def bindList[T: QueryStringBindable](key: String, params: Map[String, Seq[String]]): List[T] = {
for {
values <- params.get(key).toList
rawValue <- values
bound <- implicitly[QueryStringBindable[T]].bind(key, Map(key -> Seq(rawValue)))
value <- bound.right.toOption
} yield value
}
private def unbindList[T: QueryStringBindable](key: String, values: Iterable[T]): String = {
(for (value <- values) yield {
implicitly[QueryStringBindable[T]].unbind(key, value)
}).mkString("&")
}
/**
* Convert a Scala List[T] to Javascript array
*/
implicit def litteralOption[T](implicit jsl: JavascriptLitteral[T]) = new JavascriptLitteral[List[T]] {
def to(value: List[T]) = "[" + value.map { v => jsl.to(v)+"," } +"]"
}
}
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
// Add your own project settings here
lessEntryPoints <<= baseDirectory(_ / "app" / "assets" / "stylesheets" ** "style.less"),
routesImport += "models.QueryBinders"
)
关于scala - List[String] 的 QueryStringBinder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10464268/
我已经定义了一个枚举类型Format,它实现了QueryStringBindable。我想我已经正确地实现了它,但是在我的路由文件中,我不能将我的类型指定为路由参数,因为编译器找不到它,而且我不知道如
使用 Play 2.0.1 我定义了以下路线: GET /demo/list controllers.Demos.listDemos(page: Int ?= 0, orderBy: Int ?=
我想在我的 Play-scala 项目中使用 java.sql.Date 和 Option[java.sql.Date] 作为查询参数,这不是 Play 框架的默认设置。我使用的 Play 版本是 2
您好,我正在尝试将 models.InputTimeSheetDataStore 类型的对象列表从 View 传递到 application.java,并且我得到No QueryString bind
所以我正在使用 play 2.0,并且我试图将 double 值从我的 View 传递回 Controller 应用程序,但我得到了这个错误:没有找到 Double 类型的 QueryString B
我是一名优秀的程序员,十分优秀!