在playframework 1.x中,session只是模板中的一个隐含对象,但它似乎已经在playframework 2.0中消失了.我有办法在模板中使用会话对象吗?
谢谢.
jniPath := {
val subProjectPath = projectDependencies.value map (module => (jniPath in LocalProject(module.name)).value)
val path = libraryDependencies.value flatMap (_.name)
path ++ subProjectPath mkString File.pathSeparator
}
Run Code Online (Sandbox Code Playgroud)
有没有人有解决方法?似乎这个问题来自于, (jniPath in LocalProject(module.name)).value 但是我看不出有什么方法可以做到这是SBT的限制吗?
干杯
我刚刚开始使用Play 2.0 Framwork.我想知道基于ajax的表单提交的最佳方法是什么.目前,我的页面包含下面的表单和列表,其中应显示新条目(表单).我想通过ajax提交提交以及列表更新.
但我的第一个问题是如何通过ajax提交表单并使用表单绑定和控制器的验证.那可能吗?这样做的正确方法是什么?
谢谢,
如果我做:
val l = Seq(("un", ""), ("deux", "hehe"), ("trois", "lol"))
l map { t => t._1 + t._2 }
Run Code Online (Sandbox Code Playgroud)
没关系.
如果我做:
val l = Seq(("un", ""), ("deux", "hehe"), ("trois", "lol"))
l map { case (b, n) => b + n }
Run Code Online (Sandbox Code Playgroud)
也没关系.
但如果我这样做:
val l = Seq(("un", ""), ("deux", "hehe"), ("trois", "lol"))
l map { (b, n) => b + n }
Run Code Online (Sandbox Code Playgroud)
不起作用.
为什么我应该使用"case"关键字来使用命名元组?
我有一个嵌套对象,例如:
{
"name:"ABC",
"nest1":{
{
"field1": null,
"field2": null,
"field3": [],
"field4": {},
},
"nest2":{
"field1":"123",
"field2":null
}
}
Run Code Online (Sandbox Code Playgroud)
我想清理这个 json,并确保输出是:
{
"name:"ABC",
"nest2":{
"field1":"123"
}
}
Run Code Online (Sandbox Code Playgroud)
我写了下面的一段代码:
def withoutNullAndEmptyObj(json: JsValue): JsValue = {
json match {
case JsObject(fields) =>
if (fields.isEmpty) JsNull
else{
fields.foldLeft(new JsObject(Map()))((agg, field) =>
field match{
case (_, JsNull) => agg
case other@(name, value: JsArray) => if (value == emptyArray) agg else agg+other
case (name, value: JsObject) => if (value == emptyObject) agg else agg+(name, withoutNullAndEmptyObj(value)) …Run Code Online (Sandbox Code Playgroud) 我正在尝试为Play2/Scala中的一个发送/接收JSON的简单REST API编写测试用例.我的测试如下所示:
import org.junit.runner.RunWith
import org.specs2.matcher.JsonMatchers
import org.specs2.mutable._
import org.specs2.runner.JUnitRunner
import play.api.libs.json.{Json, JsArray, JsValue}
import play.api.test.Helpers._
import play.api.test._
import play.test.WithApplication
/**
* Add your spec here.
* You can mock out a whole application including requests, plugins etc.
* For more information, consult the wiki.
*/
@RunWith(classOf[JUnitRunner])
class APIv1Spec extends Specification with JsonMatchers {
val registrationJson = Json.parse("""{"device":"576b9cdc-d3c3-4a3d-9689-8cd2a3e84442", |
"firstName":"", "lastName":"Johnny", "email":"justjohnny@test.com", |
"pass":"myPassword", "acceptTermsOfService":true}
""")
def dropJsonElement(json : JsValue, element : String) = (json \ element).get match {
case …Run Code Online (Sandbox Code Playgroud) 考虑以下课程:
class MyClass @Inject() (ws: WSClient)(implicit executionContext: ExecutionContext)
Run Code Online (Sandbox Code Playgroud)
以及获取此类的代码:
app.injector.instanceOf[MyClass]
Run Code Online (Sandbox Code Playgroud)
从我理解的guice注入器,注入一个ExecutionContext隐含的ExecutionContext,但在某些情况下,我想给该实例一个不同的ExecutionContext
我该怎么做呢
谢谢.
我正在尝试在我的播放项目中导入scala.slick但我一直得到"对象浮动不是包scala错误的成员"
build.sbt:
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test,
"com.typesafe.slick" %% "slick" % "3.1.1",
"com.typesafe.play" %% "play-slick" % "1.1.1"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/releases/"
Run Code Online (Sandbox Code Playgroud)
我正在使用scala 2.11.6,播放2.4.x
我正在尝试在笔记本电脑(Mac OS)上的Docker容器中运行elasticsearch并在TCP端口9300上运行测试连接。
首先,我尝试在没有docker的情况下运行它:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.zip
unzip elasticsearch-5.1.1.zip
cd elasticsearch-5.1.1
echo "cluster.name: test
client.transport.sniff: false
discovery.zen.minimum_master_nodes: 1
network.host:
- _local_
- _site_
network.publish_host: _local_" > config/elasticsearch.yml
./bin/elasticsearch
Run Code Online (Sandbox Code Playgroud)
一切正常。
现在,如果我尝试使用docker:
docker run -p 9300:9300 -ti openjdk
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.zip
unzip elasticsearch-5.1.1.zip
cd elasticsearch-5.1.1
echo "cluster.name: test
client.transport.sniff: false
discovery.zen.minimum_master_nodes: 1
network.host:
- _local_
- _site_
network.publish_host: _local_" > config/elasticsearch.yml
chmod 777 -R .
useradd elastic
su elastic
./bin/elasticsearch
Run Code Online (Sandbox Code Playgroud)
它适用于第一套测试,但不适用于第二套测试:
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes were available: [{nlR3i79}{nlR3i797RuKXJqS86GExXQ}{O6ltC6a5R-asNMuvCt3c4w}{127.0.0.1}{127.0.0.1:9300}]
Run Code Online (Sandbox Code Playgroud)
干杯
我正在尝试编写一个可以采用任何无标记最终特征并返回的函数F[String]。
def apply[Api[F[_]]](implementation: Api[F[_]]): F[String] = ???
Run Code Online (Sandbox Code Playgroud)
我不明白为什么上面的内容没有编译。
以下作品。
trait Api[F[_]]
def apply[F[_]](implementation: Api[F[_]]): F[String] = ???
Run Code Online (Sandbox Code Playgroud)
但我怎样才能摆脱这个特质呢?