我使用的是play框架2.2,如何在表单中设置默认值?我希望用户看到 1000 作为默认超时:
我的表格:
val deviceForm = Form(mapping(
"name" -> nonEmptyText,
"timeout" -> number
)(Device.apply)(Device.unapply))
Run Code Online (Sandbox Code Playgroud)
视图中:
@inputText(deviceForm("name"), '_label -> "Name")
@inputText(deviceForm("timeout"), '_label -> "Timeout")
Run Code Online (Sandbox Code Playgroud) 如何从 Twitter Streaming API - POST statuses/filter 读取响应数据?我已建立连接并收到 200 状态代码,但我不知道如何阅读推文。我只想在推文到来时打印它们。
ws.url(url)
.sign(OAuthCalculator(consumerKey, requestToken))
.withMethod("POST")
.stream()
.map { response =>
if(response.headers.status == 200)
println(response.body)
}
Run Code Online (Sandbox Code Playgroud)
编辑:我找到了这个解决方案
ws.url(url)
.sign(OAuthCalculator(consumerKey, requestToken))
.withMethod("POST")
.stream()
.map { response =>
if(response.headers.status == 200){
response.body
.scan("")((acc, curr) => if (acc.contains("\r\n")) curr.utf8String else acc + curr.utf8String)
.filter(_.contains("\r\n"))
.map(json => Try(parse(json).extract[Tweet]))
.runForeach {
case Success(tweet) =>
println("-----")
println(tweet.text)
case Failure(e) =>
println("-----")
println(e.getStackTrace)
}
}
}
Run Code Online (Sandbox Code Playgroud) twitter scala playframework twitter-streaming-api playframework-2.5
我有以下代码。这是 shipFlagCountryDF 的架构
root
|-- flagcountry: string (nullable = true)
|-- max(count): long (nullable = true)
|-- min(count): long (nullable = true)
|-- avg(count): double (nullable = true)
|-- stddev_samp(count,0,0): double (nullable = false)
Run Code Online (Sandbox Code Playgroud)
以下是一些示例行:
+--------------------+----------+----------+----------+----------------------+
| flagcountry|max(count)|min(count)|avg(count)|stddev_samp(count,0,0)|
+--------------------+----------+----------+----------+----------------------+
| Cyprus| 65| 46| 55.0| 9.40744386111339|
| Luxembourg| 3| 1| 2.5| 0.9999999999999999|
| Niue| 5| 3| 4.4| 0.8944271909999159|
| Palestine| 2| 1| 1.25| 0.49999999999999994|
| Norway| 30| 18| 23.4| 5.683308895353129|
| Mongolia| 21| 15| 17.6| 2.302172886644268|
| Dominica| 1| 1| 1.0| …Run Code Online (Sandbox Code Playgroud) 我只是在研究一个带有休眠的 Play/scala 示例。我案例类我发现了一些这样的东西......
class Buddy(first: String, last: String) {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
var id: Int = _
var firstName: String = first
var lastName: String = last
def this() = this (null, null)
override def toString = id + " = " + firstName + " " + lastName
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以向我解释这一行“var id:Int = _”的含义。
这段代码中“__”的确切含义是什么。我猜它与getter方法无关,因为在这种情况下我猜getter方法名称将是id_。
提前致谢 ...
有没有办法/命令 - 我可以从 versions.sbt 文件中提取应用程序版本?
我想将 ByteArray 转换为字符串,然后将字符串转换为 ByteArray,但是在转换时值发生了变化。有人帮助解决这个问题。
人.proto:
syntax = "proto3";
message Person{
string name = 1;
int32 age = 2;
}
Run Code Online (Sandbox Code Playgroud)
sbt 编译后,它给出案例类 Person (编译时由 google protobuf 创建)
我的主课:
val newPerson = Person(
name = "John Cena",
age = 44 //output
)
println(newPerson.toByteArray) //[B@50da041d
val l = newPerson.toByteArray.toString
println(l) //[B@7709e969
val l1 = l.getBytes
println(l1) //[B@f44b405
Run Code Online (Sandbox Code Playgroud)
为什么价值观改变了?如何正确转换??
我是 Scala 环境的新手,并尝试使用“scalikejdbc”进行 SQL 集成来构建一个测试项目。这是我的 build.sbt,遵循http://scalikejdbc.org/documentation/playframework-support.html上的文档
name := """run"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.10"
libraryDependencies ++= Seq(
guice,
"org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test,
"com.h2database" % "h2" % "1.4.200", // your jdbc driver here
"org.scalikejdbc" %% "scalikejdbc" % "4.0.0",
"org.scalikejdbc" %% "scalikejdbc-config" % "4.0.0",
"org.scalikejdbc" %% "scalikejdbc-play-initializer" % "2.8.0-scalikejdbc-3.5",
"com.typesafe.play" %% "play-ws" % "2.3.1"
)
dependencyOverrides += "org.fluentlenium" % "fluentlenium-core" % "0.10.3"
// Adds additional packages …Run Code Online (Sandbox Code Playgroud) 当我从终端运行命令时:sbt run
它像这样登录控制台:
[info] welcome to sbt 1.3.13 (Azul Systems, Inc. Java 1.8.0_362)
[info] loading global plugins from /.sbt/1.0/plugins
[info] loading settings for project from plugins.sbt ...
[info] loading project definition from /demo/project
[info] loading settings for project root from build.sbt ...
[info] __ __
[info] \ \ ____ / /____ _ __ __
[info] \ \ / __ \ / // __ `// / / /
[info] / / / /_/ // // /_/ // /_/ /
[info] …Run Code Online (Sandbox Code Playgroud) 安装游戏时遇到问题!在窗户上.
按照安装指南进行操作:http://www.playframework.org/documentation/1.2.4/install
安装并设置JAVA_HOME和ANT_HOME后
在git我键入命令:
$ git clone git://github.com/playframework/play.git
$ cd play/framework
$ ant
Run Code Online (Sandbox Code Playgroud)
构建成功.但是当我输入命令时:
$ play
Run Code Online (Sandbox Code Playgroud)
它无法识别命令.
Play框架是否默认包含任何镜头支持?像Monocole或Scalaz 那样的东西.也许我不知道有推荐的替代方法(及其基本原理).
场景:我有一个案例类的不可变的,深度嵌套的对象,我想用一个在对象中某处更改的字段来复制它.
我正在寻找这样做非常简单而不需要太多样板,就像像Monocole那样的镜头库.
我很惊讶Play框架内置了任何支持.我错过了什么吗?如果没有,是否有任何已知的支持计划?