本文整理汇总了Scala中play.api.data.Forms.mapping类的典型用法代码示例。如果您正苦于以下问题:Scala mapping类的具体用法?Scala mapping怎么用?Scala mapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: MenuPerDayPerPersonForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.UUID
import play.api.data.Form
import play.api.data.Forms.{ mapping, text, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class MenuPerDayPerPersonForm(
menuPerDayUuid: List[UUID],
menuDate: List[String]
)
object MenuPerDayPerPersonForm {
implicit val menuPerDayPerPersonFormFormat: OFormat[MenuPerDayPerPersonForm] = Json.format[MenuPerDayPerPersonForm]
val menuPerDayPerPersonForm = Form(
mapping(
"menuPerDayUuid" -> list(of[UUID]),
"menuDate" -> list(text)
)(MenuPerDayPerPersonForm.apply)(MenuPerDayPerPersonForm.unapply)
)
}
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:25,代码来源:MenuPerDayPerPersonForm.scala
示例2: Products
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc._
import javax.inject.Inject
import play.api.i18n.{Messages, MessagesApi, I18nSupport}
import play.api.data.Form
import play.api.data.Forms.{mapping, longNumber, nonEmptyText}
import models.Product
class Products @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {
def list = Action { implicit request =>
val products = Product.findAll
Ok(views.html.products.list(products))
}
def show(ean: Long) = Action {
implicit request => Product.findByEan(ean).map {
// rendering product details
product => Ok(views.html.products.details(product))
}.getOrElse(NotFound) // return page 404
}
private val productForm: Form[Product] = Form(
mapping(
"ean" -> longNumber.verifying("validation.ean.duplicate", Product.findByEan(_).isEmpty), // form? field? ????
"name" -> nonEmptyText,
"description" -> nonEmptyText
)(Product.apply)(Product.unapply) // form? model ?? mapping
)
def save = Action {
implicit request => val newProductForm = productForm.bindFromRequest()
newProductForm.fold(
hasErrors = {
form => Redirect(routes.Products.newProduct()).
flashing(Flash(form.data) + ("error" -> Messages("validation.errors")))
},
success = {
newProduct => Product.add(newProduct)
val message = Messages("products.new.success", newProduct.name)
Redirect(routes.Products.show(newProduct.ean)).flashing("success" -> message)
}
)
}
def newProduct = Action {
implicit request => val form = if (request2flash.get("error").isDefined)
productForm.bind(request2flash.data)
else
productForm
Ok(views.html.products.editProduct(form))
}
}
开发者ID:makeajourney,项目名称:play-products-example,代码行数:56,代码来源:Products.scala
示例3: HomeController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import akka.actor.{ActorSystem, _}
import dao.CatDAO
import models._
import play.api.cache.CacheApi
import play.api.data.Form
import play.api.data.Forms.{mapping, text}
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json.Json
import play.api.mvc._
@Singleton
class HomeController @Inject()(implicit system: ActorSystem, catDao: CatDAO, cache: CacheApi) extends Controller {
def index = Action.async {
val actorId = cache.get[String]("actor-id_1").get
println(actorId)
val client = system.actorSelection(actorId)
client ! Json.toJson(EventB("MessageB"))
catDao.all().map {
cats => Ok(views.html.index(cats))
}
}
def insertCat = Action.async { implicit request =>
val cat: Cat = catForm.bindFromRequest.get
catDao.insert(cat).map(_ => Redirect(routes.HomeController.index))
}
def ws = Action { request => Ok(views.html.ws()) }
val catForm = Form(
mapping(
"name" -> text(),
"color" -> text()
)(Cat.apply)(Cat.unapply)
)
}
开发者ID:koduki,项目名称:example-palyframework,代码行数:45,代码来源:HomeController.scala
示例4: limit
//设置package包名称以及导入依赖的类
package com.github.stonexx.play.data
package forms
import com.github.stonexx.scala.data.Limit
import play.api.data.Forms.{optional, mapping}
import play.api.data.Mapping
trait LimitForms {
def limit[T](implicit m: Mapping[T]): Mapping[Limit[T]] = mapping(
"from" -> optional(m),
"to" -> optional(m),
"eq" -> optional(m)
)(
(from, to, eq) => Limit(from orElse eq, to orElse eq)
)(
limit => Option(limit.from, limit.to, limit.from.filter(limit.to.contains))
)
}
开发者ID:stonexx,项目名称:utils,代码行数:21,代码来源:LimitForms.scala
示例5: MenuPerDayForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.{ Date, UUID }
import play.api.data.Form
import play.api.data.Forms.{ mapping, of, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class MenuPerDayForm(
menuUuid: UUID,
date: Date
)
object MenuPerDayForm {
implicit val menuPerDayFormFormat: OFormat[MenuPerDayForm] = Json.format[MenuPerDayForm]
val menuPerDayForm = Form(
mapping(
"menuUuid" -> of[UUID],
"date" -> date(pattern = "dd-MM-yyyy")
)(MenuPerDayForm.apply)(MenuPerDayForm.unapply)
)
}
case class ListMenusPerDayForm(listUuids: List[UUID], dateStart: Date, dateEnd: Date)
object ListMenusPerDayForm {
val listMenusPerDayForm = Form(
mapping(
"uuid" -> list(of[UUID]),
"dateStart" -> date(pattern = "dd-MM-yyyy"),
"dateEnd" -> date(pattern = "dd-MM-yyyy")
)(ListMenusPerDayForm.apply)(ListMenusPerDayForm.unapply)
)
}
case class FilterMenusPerDayForm(dateStart: Date, dateEnd: Date)
object FilterMenusPerDayForm {
val filterMenusPerDayForm = Form(
mapping(
"dateStart" -> date(pattern = "dd-MM-yyyy"),
"dateEnd" -> date(pattern = "dd-MM-yyyy")
)(FilterMenusPerDayForm.apply)(FilterMenusPerDayForm.unapply)
)
}
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:48,代码来源:MenuPerDayForm.scala
示例6: ProfileForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import play.api.data.Form
import play.api.data.Forms.{ mapping, optional, text, _ }
import play.api.libs.json.{ Json, OFormat }
case class ProfileForm(
vegetarian: Boolean,
seaFoodRestriction: Boolean,
porkRestriction: Boolean,
beefRestriction: Boolean,
chickenRestriction: Boolean,
glutenRestriction: Boolean,
lactoseRestriction: Boolean,
otherRestriction: Option[String]
)
object ProfileForm {
implicit val profileFormFormat: OFormat[DishForm] = Json.format[DishForm]
val profileForm = Form(
mapping(
"vegetarian" -> boolean,
"seaFoodRestriction" -> boolean,
"porkRestriction" -> boolean,
"beefRestriction" -> boolean,
"chickenRestriction" -> boolean,
"glutenRestriction" -> boolean,
"lactoseRestriction" -> boolean,
"otherRestriction" -> optional(text)
)(ProfileForm.apply)(ProfileForm.unapply)
)
}
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:34,代码来源:ProfileForm.scala
示例7: MenuForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.UUID
import play.api.data.Form
import play.api.data.Forms.{ list, mapping, of, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class MenuForm(
menuName: String,
dishesUuid: List[UUID]
)
object MenuForm {
implicit val menuFormFormat: OFormat[MenuForm] = Json.format[MenuForm]
val menuForm = Form(
mapping(
"menuName" -> nonEmptyText,
"dishesUuid" -> list(of[UUID])
)(MenuForm.apply)(MenuForm.unapply)
)
}
case class ListMenusForm(listUuids: List[UUID])
object ListMenusForm {
val listMenusForm = Form(
mapping(
"uuid" -> list(of[UUID])
)(ListMenusForm.apply)(ListMenusForm.unapply)
)
}
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:35,代码来源:MenuForm.scala
示例8: DishForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.UUID
import play.api.data.Form
import play.api.data.Forms.{ mapping, optional, text, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class DishForm (
name: String,
description: String,
isVegetarian: Boolean = false,
hasSeaFood: Boolean = false,
hasPork: Boolean = false,
hasBeef: Boolean = false,
hasChicken: Boolean = false,
isGlutenFree: Boolean = false,
hasLactose: Boolean = false,
remarks: Option[String] = None
)
object DishForm {
implicit val dishFormFormat: OFormat[DishForm] = Json.format[DishForm]
val dishForm = Form(
mapping(
"name" -> nonEmptyText,
"description" -> nonEmptyText,
"isVegetarian" -> boolean,
"hasSeaFood" -> boolean,
"hasPork" -> boolean,
"hasBeef" -> boolean,
"hasChicken" -> boolean,
"isGlutenFree" -> boolean,
"hasLactose" -> boolean,
"remarks" -> optional(text)
)(DishForm.apply)(DishForm.unapply)
)
}
case class ListDishesForm(listUuids: List[UUID])
object ListDishesForm {
val listDishesForm = Form(
mapping(
"uuid" -> list(of[UUID])
)(ListDishesForm.apply)(ListDishesForm.unapply)
)
}
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:51,代码来源:DishForm.scala
示例9: Products
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
import play.api.i18n.{Messages, I18nSupport, MessagesApi}
import play.api.data.Form
import play.api.data.Forms.{mapping, longNumber, nonEmptyText}
import models.Product
class Products @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport{
def list = Action{ implicit request =>
val products = Product.findAll
Ok(views.html.products.list(products))
}
def show(ean: Long) = Action{ implicit request =>
Product.findByEan(ean).map{ product =>
Ok(views.html.products.details(product))
}.getOrElse(NotFound)
}
def newProduct = Action{ implicit request =>
val form = if(request.flash.get("error").isDefined)
productForm.bind(request.flash.data)
else
productForm
Ok(views.html.products.editProduct(form))
}
private val productForm: Form[Product] = Form(
mapping(
"ean" -> longNumber.verifying(
"validation.ean.duplicate", Product.findByEan(_).isEmpty),
"name" -> nonEmptyText,
"description" -> nonEmptyText
)(Product.apply)(Product.unapply)
)
def save = Action { implicit request =>
val newProductForm = productForm.bindFromRequest()
newProductForm.fold(
hasErrors = {form =>
Redirect(routes.Products.newProduct()).flashing(Flash(form.data) +
("error" -> Messages("validation.errors")))
},
success = {newProduct =>
Product.add(newProduct)
val message = Messages("products.new.success", newProduct.name)
Redirect(routes.Products.show(newProduct.ean)).flashing("success" -> message)
}
)
}
}
开发者ID:beniaminp,项目名称:PlayTutorial,代码行数:58,代码来源:Products.scala
示例10: NewLinkForm
//设置package包名称以及导入依赖的类
package models.forms
import models.LinkAddData
import play.api.data.Form
import play.api.data.Forms.{mapping, nonEmptyText, optional, text, longNumber}
import play.api.data.validation.{Constraint, Invalid, Valid}
object NewLinkForm {
private val urlRegex = "(^|[\\s.:;?\\-\\]<\\(])(https?://[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,?]+[\\w/#](\\(\\))?)(?=$|[\\s',\\|\\(\\).:;?\\-\\[\\]>\\)])"
private val urlContraint = Constraint[String] { s: String =>
if (s.matches(urlRegex))
Valid
else
Invalid("is not a valid url")
}
val form = Form(
mapping(
"url" -> nonEmptyText.verifying(urlContraint),
"name" -> optional(text),
"description" -> optional(text),
"parentId" -> optional(longNumber)
)(LinkAddData.apply)(LinkAddData.unapply)
)
}
开发者ID:agoetschm,项目名称:linkmanager,代码行数:28,代码来源:NewLinkForm.scala
示例11: index
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import models.{Person, PersonData}
import play.api._
import play.api.data.Form
import play.api.data.Forms.{mapping, of}
import play.api.data.format.Formats._
import play.api.libs.json.Json
import play.api.mvc._
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
def addPerson = Action { implicit request =>
val userForm = Form(
mapping(
"name" -> of[String]
)(PersonData.apply)(PersonData.unapply)
)
val userData = userForm.bindFromRequest.get
var person = new Person()
person.name = userData.name
person.save()
Redirect(routes.HomeController.index())
}
def getPersons = Action {
Ok(Json.toJson(Person.all()))
}
}
开发者ID:patrick-melo,项目名称:play-scala-ebean,代码行数:38,代码来源:HomeController.scala
示例12: Application
//设置package包名称以及导入依赖的类
package controllers
import dao.CatDAO
import dao.DogDAO
import javax.inject.Inject
import models.Cat
import play.api.data.Form
import play.api.data.Forms.mapping
import play.api.data.Forms.text
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.Action
import play.api.mvc.Controller
import models.Dog
class Application @Inject() (catDao: CatDAO, dogDao: DogDAO) extends Controller {
def index = Action.async {
catDao.all().zip(dogDao.all()).map {case (cats, dogs) => Ok(views.html.index(cats, dogs)) }
}
def react = Action {
Ok(views.html.react())
}
val catForm = Form(
mapping(
"name" -> text(),
"color" -> text()
)(Cat.apply)(Cat.unapply)
)
val dogForm = Form(
mapping(
"name" -> text(),
"color" -> text()
)(Dog.apply)(Dog.unapply)
)
def insertCat = Action.async { implicit request =>
val cat: Cat = catForm.bindFromRequest.get
catDao.insert(cat).map(_ => Redirect(routes.Application.index))
}
def insertDog = Action.async { implicit request =>
val dog: Dog = dogForm.bindFromRequest.get
dogDao.insert(dog).map(_ => Redirect(routes.Application.index))
}
}
开发者ID:namelos,项目名称:play-slick-boilerplate,代码行数:49,代码来源:Application.scala
示例13: ProductsController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api.mvc._
import models.Product
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.data.Form
import play.api.data.Forms.{mapping, longNumber, nonEmptyText}
import play.api.i18n.Messages
@Singleton
class ProductsController @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {
private val productForm: Form[Product] = Form(
mapping(
"ean" -> longNumber.verifying("validation.ean.duplicate", Product.findByEan(_).isEmpty),
"name" -> nonEmptyText,
"description" -> nonEmptyText
)(Product.apply)(Product.unapply)
)
def list = Action { implicit request =>
val products = Product.findAll
Ok(views.html.products.list(products))
}
def show(ean: Long) = Action { implicit request =>
Product.findByEan(ean).map { product =>
Ok(views.html.products.details(product))
}.getOrElse(NotFound)
}
def newProduct = Action { implicit request =>
val form = if (request.flash.get("error").isDefined)
productForm.bind(request.flash.data)
else
productForm
Ok(views.html.products.editProduct(form))
}
def save = Action { implicit request =>
val newProductForm = productForm.bindFromRequest()
newProductForm.fold(
hasErrors = { form =>
Redirect(routes.ProductsController.newProduct).
flashing(Flash(form.data) + ("error" -> Messages("validation.errors")))
},
success = { newProduct =>
Product.add(newProduct)
val message = Messages("products.new.success", newProduct.name)
Redirect(routes.ProductsController.show(newProduct.ean)).
flashing("success" -> message)
}
)
}
}
开发者ID:yomajkel,项目名称:scala_play_book,代码行数:61,代码来源:ProductsController.scala
示例14: ItemController
//设置package包名称以及导入依赖的类
package controllers
import controllers.Auth.Secured
import forms.CreateOrderForm
import play.api.data.Form
import play.api.data.Forms.{list, longNumber, mapping, number}
import play.api.mvc.Controller
object ItemController extends Controller with Secured {
val orderForm = Form(
mapping(
"itemID" -> longNumber,
"quantity" -> number,
"size" -> number,
"extraID" -> list(longNumber)
)(CreateOrderForm.apply)(CreateOrderForm.unapply))
def showItems(categoryID: Long) = withUser_Customer { user => implicit request =>
Ok(views.html.welcomeUser(controllers.ItemController.orderForm, user, categoryID))
}
}
开发者ID:Sup3rdom,项目名称:grp1A-pizza,代码行数:23,代码来源:ItemController.scala
示例15: SessionType
//设置package包名称以及导入依赖的类
package models
import play.api.data._
import play.api.data.Forms.{mapping, _}
import play.api.libs.json.{Json, OWrites}
case class SessionType(
id: Int,
name: String,
points: Seq[Int],
incidentsLimit: Int,
penaltyPoints: Int
) {}
object SessionType {
implicit val writes: OWrites[SessionType] = Json.writes[SessionType]
def getMappingWithMandatoryId() : Mapping[SessionType] = {
mapping(
"id" -> number,
"name" -> nonEmptyText,
"points" -> seq(number),
"incidentsLimit" -> number,
"penaltyPoints" -> number
)(SessionType.apply)(SessionType.unapply)
}
def getMapping() = mapping(
"id" -> number,
"name" -> nonEmptyText,
"points" -> seq(number),
"incidentsLimit" -> number,
"penaltyPoints" -> number
)(SessionType.apply)(SessionType.unapply)
val form: Form[SessionType] = Form(
getMapping()
)
}
开发者ID:jean-philippe-bousselin,项目名称:orca-api,代码行数:41,代码来源:SessionType.scala
注:本文中的play.api.data.Forms.mapping类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论