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

Scala longNumber类代码示例

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

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



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

示例1: 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


示例2: 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


示例3: 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


示例4: 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


示例5: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala AssertionsForJUnit类代码示例发布时间:2022-05-23
下一篇:
Scala Buffer类代码示例发布时间: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