3

내 Play-scala 프로젝트에서 java.sql.Date 및 Option [java.sql.Date]을 쿼리 매개 변수로 사용하고 싶습니다. Play 프레임 워크에서 기본으로 제공됩니다. 내가 사용하는 Play 버전은 2.4.3입니다. 나는 (거친) 수업을 듣고있다. 내가 예를 들어, 옵션 [날짜]와 쿼리 매개 변수를 정의하면Play 2.4.3의 범위에 사용자 정의 QueryStringBindable이 있음

object CustomBinders extends { 
    val dateFormat = ISODateTimeFormat.date() 

    implicit def dateBinder: QueryStringBindable[Date] = new QueryStringBindable[Date] { 
    def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, Date]] = { 
     val dateString: Option[Seq[String]] = params.get(key) 
     try { 
     Some(Right(new Date(dateFormat.parseDateTime(dateString.get.head).getMillis))) 
     } catch { 
     case e: IllegalArgumentException => Option(Left(dateString.get.head)) 
     } 
    } 

    def unbind(key: String, value: Date): String = { 
     dateFormat.print(value.getTime) 
    } 
    } 
} 

그런 다음 Build.scala에 나는 그러나

import play.sbt.routes.RoutesKeys 

object Build extends Build { 
    RoutesKeys.routesImport += "binders.CustomBinders.dateBinder" 
    RoutesKeys.routesImport += "binders.CustomBinders.optionDateBinder" 

을 가지고, 나는 오류

No QueryString binder found for type Option[java.sql.Date]. Try to implement an implicit QueryStringBindable for this type. 
받고 있어요

분명히 범위가 아닙니다. 바인더가 범위 내에 존재하도록 바인더를 어떻게 정의해야합니까? 나는 이것에 대한 2.4 문서를 찾을 수 없다. 그러나 2.5-documentation은 Build.scala에 추가 할 필요가 있다고 말하지 않는다.

답변

3

그래서 appendantly Build.scala는 적절한 장소가 아니었다. 문서는 그것을 거기에 넣으라고 말한다. when build.sbt

routesImport += "binders.CustomBinders._" 

프로젝트가 올바르게 컴파일됩니다. 바인더에 대한 원래 게시물의 일부 오류가 수정되었습니다.