ãåãPlay 2.x ã® QueryStringBindable, PathBindable ã«ã¤ãã¦
å æ¥ Play 2.x の QueryStringBindable, PathBindable について - tototoshiの日記 㧠joda-time ç¨ã« QueryStringBindable[T] ãå®ç¾©ãã¦éã³ã¾ãããããããã©ã¤ãã©ãªåãã¾ããããèªç±ã«ã使ãä¸ããã
tototoshi/play-joda-routes-binder · GitHub
è¨å®ãå ããã ãã§ã
val main = play.Project(appName, appVersion, appDependencies).settings( libraryDependencies ++= Seq( "com.github.tototoshi" %% "play-joda-routes-binder" % "0.1.0" ), routesImport += "com.github.tototoshi.play2.routes.JodaRoutes._" )
conf/routes 㧠LocalDate, DateTime ã使ããããã«ãªãã¾ãããã£ãã!
GET /list controllers.Application.index(date: org.joda.time.LocalDate) GET /entry/$date<[0-9]+> controllers.Application.entry(date: org.joda.time.LocalDate)
ãã©ã¼ããããå¤ãã
æ¥ä»ã®ããã©ã«ãã®ãã©ã¼ããã㯠yyyyMMdd ã«ãã¦ããã¾ããyyyyMMdd ãã ã¼ãyyMMdd ãããã£ã¦äººã¯æ¬¡ã®ããã«ãã¾ãã
object MyRoutes { val myJodaRoutes = new JodaRoutes { override val format: String = "yyMMdd" } }
ããã Build.scala ã«æ¸ãã¾ãã
routesImport += "MyRoutes.myJodaRoutes._"
LocalDate ã ã使ããããDateTime ã ã使ããããï¼ã¤ã®ãã©ã¼ããããåããããã£ã¦äººã¯ JodaRoutes ã®å¤ããã« JodaLocalDateRoutes, JodaDateTimeRoutes ã使ã£ã¦ãã ããã
è¦æ
ããæ¬å½ã¯ Play æ¬ä½ã« pull request éãããã£ããã§ãããä»ã® routesImport ã®ä»çµã¿ããã¡ãã¡ããã¦ãã¡ã§ããã
Play æ¬ä½ã«ããã©ã§ QueryStringBindable[LocalDate] ããã£ãã¨ãã¾ãã
ããã«ã¦ã¼ã¶ã¼ãæ°ãã«å¥ãã©ã¼ãããã® QueryStringBindable[LocalDate] ãå®ç¾©ãã¾ãã
ããã¨ãããã2ã¤ã® QueryStringBindable[LocalDate] ãã¶ã¤ãã£ã¦è§£æ±ºã§ãã¾ããããªãã¦ãã£ãã
ã¨ããããã§ãããã¸ãã® implict ã¹ã³ã¼ããã¦ã¼ã¶ã¼ã調æ´ã§ããä»çµã¿ããªãã¨ãªããªãã¤ããã§ãã