• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala PathBindable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中play.api.mvc.PathBindable的典型用法代码示例。如果您正苦于以下问题:Scala PathBindable类的具体用法?Scala PathBindable怎么用?Scala PathBindable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PathBindable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: MultipartPostResponses200

//设置package包名称以及导入依赖的类
package form_data


    import java.io.File
    import scala.math.BigInt

    import de.zalando.play.controllers.PlayPathBindables


//noinspection ScalaStyle
package yaml {


    case class MultipartPostResponses200(name: BothPostResponses200Name, year: BothPostYear, fileSize: BothPostYear, fileName: BothPostResponses200Name) 
    case class BothPostResponses200(name: BothPostResponses200Name, year: BothPostYear, avatarSize: BothPostYear, ringtoneSize: BothPostYear) 


    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    import de.zalando.play.controllers.MissingDefaultWrites
    object ResponseWrites extends MissingDefaultWrites {
    implicit val BothPostResponses200Writes: Writes[BothPostResponses200] = new Writes[BothPostResponses200] {
        def writes(ss: BothPostResponses200) =
          Json.obj(
            "name" -> ss.name, 
            "year" -> ss.year, 
            "avatarSize" -> ss.avatarSize, 
            "ringtoneSize" -> ss.ringtoneSize
          )
        }
    implicit val MultipartPostResponses200Writes: Writes[MultipartPostResponses200] = new Writes[MultipartPostResponses200] {
        def writes(ss: MultipartPostResponses200) =
          Json.obj(
            "name" -> ss.name, 
            "year" -> ss.year, 
            "fileSize" -> ss.fileSize, 
            "fileName" -> ss.fileName
          )
        }
    }
}

// should be defined after the package because of the https://issues.scala-lang.org/browse/SI-9922

//noinspection ScalaStyle
package object yaml {

    type MultipartPostAvatar = Option[File]
    type BothPostResponses200Name = Option[String]
    type BothPostYear = Option[BigInt]


import play.api.mvc.{QueryStringBindable, PathBindable}

    implicit val bindable_FileQuery = PlayPathBindables.queryBindableFile
    implicit val bindable_BigIntQuery = PlayPathBindables.queryBindableBigInt
    implicit val bindable_OptionFileQuery: QueryStringBindable[Option[File]] = PlayPathBindables.createOptionQueryBindable[File]
    implicit val bindable_OptionBigIntQuery: QueryStringBindable[Option[BigInt]] = PlayPathBindables.createOptionQueryBindable[BigInt]

} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:61,代码来源:form_data_yaml.scala


示例2: ErrorModel

//设置package包名称以及导入依赖的类
import de.zalando.play.controllers.ArrayWrapper

    import de.zalando.play.controllers.PlayPathBindables


//noinspection ScalaStyle
package simple_petstore_api_yaml {


    case class ErrorModel(code: Int, message: String) 
    case class Pet(id: Long, name: String, tag: NewPetTag) 
    case class NewPet(name: String, id: NewPetId, tag: NewPetTag) 


    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    import de.zalando.play.controllers.MissingDefaultReads
    object BodyReads extends MissingDefaultReads {
        implicit val NewPetReads: Reads[NewPet] = (
            (JsPath \ "name").read[String] and (JsPath \ "id").readNullable[Long] and (JsPath \ "tag").readNullable[String]
        )(NewPet.apply _)
    }

    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    import de.zalando.play.controllers.MissingDefaultWrites
    object ResponseWrites extends MissingDefaultWrites {
    implicit val PetWrites: Writes[Pet] = new Writes[Pet] {
        def writes(ss: Pet) =
          Json.obj(
            "id" -> ss.id, 
            "name" -> ss.name, 
            "tag" -> ss.tag
          )
        }
    }
}

// should be defined after the package because of the https://issues.scala-lang.org/browse/SI-9922

//noinspection ScalaStyle
package object simple_petstore_api_yaml {

    type PetsIdDeleteResponses204 = Null
    type NewPetTag = Option[String]
    type PetsGetLimit = Option[Int]
    type NewPetId = Option[Long]
    type PetsGetTagsOpt = ArrayWrapper[String]
    type PetsGetResponses200 = Seq[Pet]
    type PetsGetTags = Option[PetsGetTagsOpt]


import play.api.mvc.{QueryStringBindable, PathBindable}

    implicit val bindable_OptionIntQuery: QueryStringBindable[Option[Int]] = PlayPathBindables.createOptionQueryBindable[Int]
    implicit val bindable_ArrayWrapperStringQuery: QueryStringBindable[ArrayWrapper[String]] = PlayPathBindables.createArrayWrapperQueryBindable[String]("csv")
    implicit val bindable_OptionPetsGetTagsOptQuery: QueryStringBindable[Option[PetsGetTagsOpt]] = PlayPathBindables.createOptionQueryBindable[PetsGetTagsOpt]

} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:60,代码来源:simple_petstore_api_yaml.scala


示例3: Company

//设置package包名称以及导入依赖的类
package models

import java.util.Date

import com.github.stonexx.play.mvc.binders.enum._
import com.github.stonexx.scala.data.OrderedEnumeration
import play.api.mvc.{QueryStringBindable, PathBindable}

case class Company(id: Option[Long], name: String)

case class Computer(
  id: Option[Long] = None,
  name: String,
  introduced: Option[Date] = None,
  discontinued: Option[Date] = None,
  companyId: Option[Long] = None
)

object Computer {
  object forms {
    object Sorts extends OrderedEnumeration {
      type Sorts = Value

      val Id           = Value
      val Name         = Value
      val Introduced   = Value
      val Discontinued = Value
      val Company      = Value

      implicit val pathBindable       : PathBindable[Ordered]        = enumOrderedPathBindable(this)
      implicit val queryStringBindable: QueryStringBindable[Ordered] = enumOrderedQueryStringBindable(this)
    }
  }
} 
开发者ID:stonexx,项目名称:utils,代码行数:35,代码来源:Models.scala


示例4: Task

//设置package包名称以及导入依赖的类
package models

import com.github.stonexx.play.mvc.binders.enum._
import com.github.stonexx.scala.data.OrderedEnumeration
import play.api.libs.json.{Json, OFormat}
import play.api.mvc.{PathBindable, QueryStringBindable}

case class Task(id: Option[Long], label: Option[String])

object Task {
  implicit val jsonFormat: OFormat[Task] = Json.format[Task]

  object forms {
    import play.api.data._
    import play.api.data.Forms._

    val labelForm = Form(
      "label" -> nonEmptyText(maxLength = 20)
    )

    object Sorts extends OrderedEnumeration {
      type Sorts = Value
      val Id    = Value
      val Label = Value

      implicit val pathBindable       : PathBindable[Ordered]        = enumOrderedPathBindable(this)
      implicit val queryStringBindable: QueryStringBindable[Ordered] = enumOrderedQueryStringBindable(this)
    }
  }
} 
开发者ID:stonexx,项目名称:utils,代码行数:31,代码来源:Task.scala


示例5: enumIdPathBindable

//设置package包名称以及导入依赖的类
package com.github.stonexx.play.mvc.binders

import com.github.stonexx.scala.data.OrderedEnumeration
import com.github.stonexx.scala.util.string._
import play.api.mvc.{QueryStringBindable, PathBindable}

trait EnumBinders {

  def enumIdPathBindable[E <: Enumeration](enum: E): PathBindable[E#Value] = new PathBindable.Parsing[E#Value](
    value => enum(value.toInt), _.id.toString,
    (key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
  )

  def enumIdQueryStringBindable[E <: Enumeration](enum: E): QueryStringBindable[E#Value] = new QueryStringBindable.Parsing[E#Value](
    value => enum(value.toInt), _.id.toString,
    (key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
  )

  def enumNamePathBindable[E <: Enumeration](enum: E): PathBindable[E#Value] = new PathBindable.Parsing[E#Value](
    value => enum.values.find(_.toString.camelToUnderscore == value.camelToUnderscore).get, _.toString,
    (key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
  )

  def enumNameQueryStringBindable[E <: Enumeration](enum: E): QueryStringBindable[E#Value] = new QueryStringBindable.Parsing[E#Value](
    value => enum.values.find(_.toString.camelToUnderscore == value.camelToUnderscore).get, _.toString,
    (key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
  )

  def enumOrderedPathBindable[E <: OrderedEnumeration](enum: E): PathBindable[E#Ordered] = new PathBindable.Parsing[E#Ordered](
    enum.Ordered.parse(_), _.toString,
    (key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum.getClass.getName, classOf[OrderedEnumeration].getSimpleName, e.getMessage)
  )

  def enumOrderedQueryStringBindable[E <: OrderedEnumeration](enum: E): QueryStringBindable[E#Ordered] = new QueryStringBindable.Parsing[E#Ordered](
    enum.Ordered.parse(_), _.toString,
    (key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum.getClass.getName, classOf[OrderedEnumeration].getSimpleName, e.getMessage)
  )

  // aliases

  @inline def enumPathBindable[E <: Enumeration](enum: E): PathBindable[E#Value] = enumNamePathBindable(enum)
  @inline def enumQueryStringBindable[E <: Enumeration](enum: E): QueryStringBindable[E#Value] = enumNameQueryStringBindable(enum)
} 
开发者ID:stonexx,项目名称:utils,代码行数:44,代码来源:EnumBinders.scala


示例6: URN

//设置package包名称以及导入依赖的类
package models
import play.api.mvc.PathBindable
import play.modules.reactivemongo.json._


case class URN(namespace:String="",domain:String="",textgroup:String="",work:String="",edition:String="",passage:String="",sentence:String="")

object URN {
  val sentence = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)\\.([^:^\\.]+):([^:]+):([^:]+)".r
  val passage = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)\\.([^:^\\.]+):([^:]+)".r
  val edition = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)\\.([^:^\\.]+)".r
  val work = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)".r
  val textgroup = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)".r
  val domain = "urn:([^:^\\.]+):([^:^\\.]+)".r
  val namespace = "^urn:([^:^\\.]+)$".r

  def apply(urn: String) = urn match {
    case sentence(a, b, c, d, e, f, g) => new URN(a, b, c, d, e, f, g)
    case passage(a, b, c, d, e, f) => new URN(a, b, c, d, e, f)
    case edition(a, b, c, d, e) => new URN(a, b, c, d, e)
    case work(a, b, c, d) => new URN(a, b, c, d)
    case textgroup(a, b, c) => new URN(a, b, c)
    case domain(a, b) => new URN(a, b)
    case namespace(a) => new URN(a)
    case _ => new URN("")
  }

  implicit def urnPathBindable(implicit stringBinder:PathBindable[String]):PathBindable[models.URN] = new PathBindable[models.URN] {

    override def bind(key:String, value:String):Either[String,models.URN] = for {
      id <- stringBinder.bind(key, value).right
    } yield models.URN(value)

    override def unbind(key: String, value: models.URN): String = value match {
      case URN(ns,"","","","","","") => "urn:"+ns
      case URN(ns,dm,"","","","","") => "urn:"+ns+":"+dm
      case URN(ns,dm,tg,"","","","") => "urn:"+ns+":"+dm+":"+tg
      case URN(ns,dm,tg,wk,"","","") => "urn:"+ns+":"+dm+":"+tg+"."+wk
      case URN(ns,dm,tg,wk,ed,"","") => "urn:"+ns+":"+dm+":"+tg+"."+wk+"."+ed
      case URN(ns,dm,tg,wk,ed,ps,"") => "urn:"+ns+":"+dm+":"+tg+"."+wk+"."+ed+":"+ps
      case URN(ns,dm,tg,wk,ed,ps,sn) => "urn:"+ns+":"+dm+":"+tg+"."+wk+"."+ed+":"+ps+"."+sn
      case _ => "urn:"
    }

  }
}
case class Word(id:String, form:String, lemma:String, morphology:Map[String,String], head:String, relation:String)

case class Sentence(_id:URN,words:Seq[Word])

// case class Adress(val scheme:String, )

object JsonFormats {
  import play.api.libs.json.Json
  implicit val urnFormat = Json.format[URN]
  implicit val wordFormat = Json.format[Word]
  implicit val sentenceFormat = Json.format[Sentence]
} 
开发者ID:fbaumgardt,项目名称:manifold_,代码行数:59,代码来源:CTS.scala


示例7: EmprefBindable

//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.models

import play.api.mvc.PathBindable
import uk.gov.hmrc.domain.EmpRef

import scala.util.{Failure, Success, Try}

object EmprefBindable extends PathBindable[EmpRef] {
  override def bind(key: String, value: String): Either[String, EmpRef] = Try(EmpRef.fromIdentifiers(value)) match {
    case Success(e) => Right(e)
    case Failure(t) => Left(t.getMessage)
  }

  override def unbind(key: String, e: EmpRef): String = s"${e.taxOfficeNumber}/${e.taxOfficeReference}"
}

object PlayBindings {
  implicit val emprefBindable = EmprefBindable
} 
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:20,代码来源:PlayBindings.scala


示例8: loginBinder

//设置package包名称以及导入依赖的类
package commons.controllers

import commons.models.Login
import play.api.mvc.{PathBindable}

import scala.util.Right

package object binders {
  implicit def loginBinder(implicit stringBinder: PathBindable[String]) = new PathBindable[Login] {

    override def bind(key: String, value: String) : Either[String, Login] = {
      stringBinder.bind("login", value) match {
        case Right(login) => Right(Login(login))
        case _ => Left("Unable to bind login.")
      }
    }

    override def unbind(key: String, login: Login): String = stringBinder.unbind("login", login.value)

  }
} 
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:22,代码来源:package.scala


示例9: bind

//设置package包名称以及导入依赖的类
package com.clemble.loveit.payment

import java.time.YearMonth

import play.api.mvc.PathBindable

package object controller {

  implicit val stringToYearMonth: PathBindable[YearMonth] = new PathBindable[YearMonth] {

    override def bind(key: String, value: String): Either[String, YearMonth] = {
      val yom = value.split("/")
      if (yom.length == 2) {
        Right(YearMonth.of(yom(0).toInt, yom(1).toInt))
      } else {
        Left(value)
      }
    }

    override def unbind(key: String, value: YearMonth): String = {
      s"${value.getYear}/${value.getMonthValue}"
    }
  }

} 
开发者ID:thankyo,项目名称:thank,代码行数:26,代码来源:package.scala


示例10: PathBinders

//设置package包名称以及导入依赖的类
package utils.extension

import play.api.mvc.PathBindable

object PathBinders {
  implicit def bindableOption[T: PathBindable] = new PathBindable[Option[T]] {
    def bind(key: String, value: String): Either[String, Option[T]] =
      implicitly[PathBindable[T]]
        .bind(key, value)
        .fold(left => Left(left), right => Right(Some(right)))
    def unbind(key: String, value: Option[T]): String =
      value.map(_.toString).getOrElse("")
  }
} 
开发者ID:jessica1421,项目名称:HD-Cignal,代码行数:15,代码来源:PathBinders.scala


示例11: AppPathBinders

//设置package包名称以及导入依赖的类
package helpers

import models.PK
import play.api.mvc.PathBindable


object AppPathBinders {
  implicit def pkPathBindable(implicit _pkBinder: PathBindable[String]) = new PathBindable[PK] {

    def bind(key: String, value: String): Either[String, PK] =
      for {
        pk <- _pkBinder.bind(key, value).right
      } yield PK(pk)

    def unbind(key: String, pk: PK): String =
      _pkBinder.unbind(key, pk.id.toString)
  }
} 
开发者ID:pawank,项目名称:PlayRestAPIWithTests,代码行数:19,代码来源:PathBinders.scala


示例12: BSONObjectIDPathBindable

//设置package包名称以及导入依赖的类
import models._
import play.api.mvc.PathBindable
import reactivemongo.bson.BSONObjectID

import scala.util.{Failure, Success}

package object binders {

  implicit object BSONObjectIDPathBindable extends PathBindable[Id] {
    val b = implicitly[PathBindable[String]]

    def bind(key: String, value: String): Either[String, Id] = {
      b.bind(key, value).right.flatMap { v =>
        BSONObjectID.parse(v) match {
          case Success(bson) => Right(bson)
          case Failure(ex) => Left("Error parse id from request.")
        }
      }
    }


    def unbind(key: String, value: Id): String =
      b.unbind(key, value.stringify)
  }

} 
开发者ID:arakcheev,项目名称:exo-2016-site,代码行数:27,代码来源:package.scala


示例13: queryStringBinder

//设置package包名称以及导入依赖的类
package com.talenthouse.enum

import play.api.libs.json.{ Json, JsString }
import play.api.mvc.{ JavascriptLiteral, PathBindable, QueryStringBindable }

import com.netaporter.uri.{ PathPart, QueryString }
import com.netaporter.uri.config.UriConfig

trait SealedBindableEnumeration {
  self: BaseSealedEnumeration =>

  implicit def queryStringBinder = new QueryStringBindable[Value] {
    def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, Value]] = {
      for {
        values <- params.get(key)
        value <- values.headOption
      } yield {
        withName(value)
          .toRight(s"Invalid value for $key: $value")
      }
    }

    def unbind(key: String, o: Value): String = {
      QueryString(Seq((key, Some(o.value))))
        .queryToString(UriConfig.default)
        .drop(1) // Drop leading `?'
    }
  }

  implicit def pathBindable = new PathBindable[Value] {
    def unbind(key: String, value: Value): String = {
      PathPart(value.value)
        .partToString(UriConfig.default)
    }

    def bind(key: String, value: String): Either[String, Value] = {
      withName(value)
        .toRight(s"Invalid value for $key: $value")
    }
  }

  implicit def jsLiteral: JavascriptLiteral[Value] = new JavascriptLiteral[Value] {
    def to(value: Value) = Json.stringify(JsString(value.value))
  }
} 
开发者ID:talenthouse-dev,项目名称:sealed-enumerations,代码行数:46,代码来源:PlayBindable.scala


示例14: Binders

//设置package包名称以及导入依赖的类
package org.splink.pagelets

import play.api.mvc.PathBindable

object Binders {

  implicit object PathBindableSymbol extends PathBindable[Symbol] {
    def bind(key: String, value: String) = try {
      Right(Symbol(value))
    } catch {
      case _: Throwable =>
        Left(s"Can't create a Symbol from '$key'")
    }

    def unbind(key: String, value: Symbol): String = value.name
  }

} 
开发者ID:splink,项目名称:pagelets,代码行数:19,代码来源:Binders.scala


示例15: Binders

//设置package包名称以及导入依赖的类
package controllers.converters

import models.{CommentId, UserId}
import play.api.mvc.PathBindable

object Binders {

  implicit val userId: PathBindable[UserId] = new PathBindable[UserId] {
    override def bind(key: String, value: String) = Right(UserId(value.toLong))
    override def unbind(key: String, value: UserId) = value.value.toString
  }

  implicit val commentId: PathBindable[CommentId] = new PathBindable[CommentId] {
    override def bind(key: String, value: String) = Right(CommentId(value.toLong))
    override def unbind(key: String, value: CommentId) = value.value.toString
  }
} 
开发者ID:Antanukas,项目名称:play-reactive-workshop,代码行数:18,代码来源:Binders.scala



注:本文中的play.api.mvc.PathBindable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala DecisionTreeRegressor类代码示例发布时间:2022-05-23
下一篇:
Scala StopWordsRemover类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap