小编Sch*_*rdt的帖子

在Scala中对密封特性进行迭代?

我只是想知道是否有可能在Scala中迭代密封的特征?如果没有,为什么不可能?由于特性是密封的,应该可以吗?

我想做的是这样的:

sealed trait ResizedImageKey {

  /**
   * Get the dimensions to use on the resized image associated with this key
   */
  def getDimension(originalDimension: Dimension): Dimension

}

case class Dimension(width: Int,  height: Int)

case object Large extends ResizedImageKey {
  def getDimension(originalDimension: Dimension) = Dimension(1000,1000)
}

case object Medium extends ResizedImageKey{
  def getDimension(originalDimension: Dimension) = Dimension(500,500)
}

case object Small extends ResizedImageKey{
  def getDimension(originalDimension: Dimension) = Dimension(100,100)
}
Run Code Online (Sandbox Code Playgroud)

通过给枚举值赋予实现,我可以用Java完成.Scala中有同等的东西吗?

enumeration scala sealed scala-macros

38
推荐指数
3
解决办法
1万
查看次数

Play应用程序中测试的资源目录

我需要一些Scala Play 2.0应用程序中的测试资源(文本文件).我在哪里可以放这些文件?

在maven应用程序中,我会将它们放入src/test/resources,但我在Play文档中找不到有关同等目录的任何内容.

我可以将它们放在conf目录中,但我在测试应用程序时只需要它们.

scala sbt playframework playframework-2.0

24
推荐指数
1
解决办法
5579
查看次数

如何在java play框架中获取查询字符串参数?

我是java play框架的新手.我已经设置了所有正常路线,如/ something /:somthingValue和所有其他路线.现在我想创建路由接受查询参数,如

/东西?X = 10&y = 20&Z = 30

在这里,我希望在"?"之后获得所有参数 as key ==> value pair.

java request.querystring playframework playframework-2.0

21
推荐指数
3
解决办法
4万
查看次数

无法使用Action.async测试控制器

我正在尝试测试控制器,它正在使用新的Action.async.下面的文档我已经排除了控制器下的部分我想测试用类型引用来分隔特征:

trait UserController { this: Controller =>
  def index() = Action { /* snip */ }
  def register() = Action.async(parse.json) { request => /* snip */ }
}
Run Code Online (Sandbox Code Playgroud)

文档说明我应该将其测试为:

object UsersControllerSpec extends PlaySpecification with Results {
  class TestController() extends Controller with UserController
    "index action" should {
      "should be valid" in {
        val controller = new TestController()
        val result: Future[SimpleResult] = controller.index().apply(FakeRequest())
        /* assertions */
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

对于index()方法它完美地工作,不幸的是我无法做同样的事情register(),因为在它上面应用FakeRequest返回的实例Iteratee[Array[Byte], SimpleResult].我注意到它有 …

scala playframework specs2 playframework-2.2

12
推荐指数
2
解决办法
3300
查看次数

如何以xunit格式制作播放框架(2.1)导出测试结果

使用该剧!framework(play2) - 我正在通过"play test"运行测试.

这样可以打印结果 - 但我也希望将结果放在xunit"XML"格式中,以便所有CI服务器都能理解如何以图形方式报告.

xunit sbt playframework jenkins playframework-2.1

8
推荐指数
1
解决办法
1244
查看次数

sbt中未解决的依赖关系

运行我的sbt构建,我得到以下未解决的依赖项.

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.typesafe.play#sbt-link;2.2.0: not found
[warn]  :: com.typesafe.play#play-exceptions;2.2.0: not found
[warn]  :: com.typesafe.play#routes-compiler_2.10;2.2.0: not found
[warn]  :: com.typesafe.play#templates-compiler_2.10;2.2.0: not found
[warn]  :: com.typesafe.play#console_2.10;2.2.0: not found
[warn]  :: net.contentobjects.jnotify#jnotify;0.94: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
Run Code Online (Sandbox Code Playgroud)

我的项目结构如下所示:

parent
 |
  --> sbtApp1
  --> playApp
  --> sbtApp2
  --> project
      --> Build.scala
      --> plugins.sbt
  --> build.sbt
Run Code Online (Sandbox Code Playgroud)

我的父/ project/plugins.sbt具有以下内容: addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

我将以下行添加到parent/build.sbt,但我仍然遇到编译时失败.

libraryDependencies += "play" % "play_2.10" % "2.1.0"

dependency-management sbt playframework

7
推荐指数
1
解决办法
1万
查看次数

宏,拼接和模式匹配

有没有办法在模式匹配中使用宏的参数?我想这样做:

def extr(X:AnyRef) = macro extrImpl

def extrImpl(c:Context)(X:c.Expr[AnyRef]):c.Expr[AnyRef] = {
  import c.universe._

  val tree = reify {
    new {
      def unapply(x:String):Option[String] = x match {
        case X.splice => Some(x) //error
        case _ => None
      }
    }
  }.tree
  c.Expr(c.typeCheck(tree))
}
Run Code Online (Sandbox Code Playgroud)

但不幸的是编译器说"需要稳定的标识符,但X.splice发现了".通常,人们可以通过首先分配val来解决这个问题,例如:

val XX = X.splice
Run Code Online (Sandbox Code Playgroud)

但当然,这也不适用于拼接.

macros scala pattern-matching scala-2.10 scala-macros

6
推荐指数
1
解决办法
754
查看次数

资产已定义为对象资产

我正在为Play Subproject功能进行更多扩展测试,如下所述:http://www.playframework.com/documentation/2.0/SBTSubProjects.但是我收到了错误:

Assets is already defined as object Assets
Run Code Online (Sandbox Code Playgroud)

在github上托管的示例应用程序:https://github.com/adis-me/PlayStrap

我已经为我的子项目定义了一个Asset控制器,如下所述:资产控制器描述,即使是主项目,但错误仍然会弹出.我的项目有什么问题?

调节器

package com.company.playstrap.controllers;

import controllers.AssetsBuilder;

public class Assets {

    public static controllers.AssetsBuilder delegate = new AssetsBuilder();

}
Run Code Online (Sandbox Code Playgroud)

路由文件

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                               com.company.playstrap.controllers.Application.index()

# Include sub projects
-> /common                              common.Routes
-> /admin                               admin.Routes
-> /website                             website.Routes

# Map static resources from the /public folder …
Run Code Online (Sandbox Code Playgroud)

playframework playframework-2.0 playframework-2.1

6
推荐指数
1
解决办法
5328
查看次数

是否有404页面的控制器(Play!Framework)

我正在玩Play!框架1.2.4并且创建静态404页面没有问题.但是,我想让404页面更有活力.

404页面是否有"控制器"?如果没有,我在哪里可以完成传统控制器中的所有逻辑?

playframework playframework-1.x

5
推荐指数
1
解决办法
3603
查看次数

以下版本中存在冲突的跨版本后缀:org.scala-stm:scala-stm

在我结束时,我有以下设置

C:>哪里玩C:\ apps\play-2.2.0\play C:\ apps\play-2.2.0\play.bat

C:> scala C:\ apps\scala\bin\scala C:\ apps\scala\bin\scala.bat


Scala -version> Scala代码运行器版本2.10.2 - 版权所有2002-2013,LAMP/EPFL

播放 - 版本>

使用Scala 2.10.2(运行Java 1.7.0_21)构建的2.2.0,http: //www.playframework.com

这不是一个游戏应用程序!

用于play new在当前目录中创建新的Play应用程序,或转到现有应用程序并使用启动开发控制台play.

您还可以在http://www.playframework.com上浏览完整的文档.


当我在我的播放提示>重新加载,更新时运行时,我收到以下错误

[error] Modules were resolved with conflicting cross-version suffixes in     {file:/C:/<filepat>}<appname>:
[error]    org.scala-stm:scala-stm _2.10, _2.10.0
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) Conflicting cross-version suffixes in: org.scala-stm:scala-stm
[error] Total time: 7 s, completed Oct 18, 2013 1:33:41 PM
[modelingApp] $ …
Run Code Online (Sandbox Code Playgroud)

build sbt playframework

5
推荐指数
1
解决办法
3618
查看次数

PlayFramework多个SLF4J绑定

我正在尝试完成一些模型的基本单元测试.但是我收到以下错误.现在看来我有两个SLF4J绑定.这是因为我使用的Mahout有一个版本的SLF4J,Play有自己的版本.

谁能告诉我如何解决这个问题?

SLF4J:请参阅http://www.slf4j.org/codes.html#multiple_bindings以获取解释.SLF4J:在类路径上检测到jcl-over-slf4j.jar和slf4j-jcl.jar,抢占StackOverflowError.SLF4J:有关详细信息,另请参见http://www.slf4j.org/codes.html#jclDelegationLoop.

java.lang.ExceptionInInitializerError
at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:82)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:51)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
at play.api.Logger$.<init>(Logger.scala:178)
at play.api.Logger$.<clinit>(Logger.scala)
at play.api.Application.<init>(Application.scala:106)
at play.api.test.FakeApplication.<init>(Fakes.scala:141)
at play.test.FakeApplication.<init>(FakeApplication.java:24)
at play.test.Helpers.fakeApplication(Helpers.java:86)
at databaseTest.startApp(databaseTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Caused by: java.lang.IllegalStateException: Detected both jcl-over-slf4j.jar AND slf4j-jcl.jar on the class path, …
Run Code Online (Sandbox Code Playgroud)

java slf4j sbt playframework playframework-2.0

4
推荐指数
1
解决办法
2614
查看次数

PlayFramework 2.1中的多个FieldConstructor?

我正在尝试在scala文档中构建自定义FieldConstructor.

我遵循指示,建立一个twitterBootstrapInput.scala.html,它的工作原理......

这是我的输出:

输出截图

问题出现了:

我希望@helper.inputRadioGroup跨度"水平",而不是垂直.

(由于twitterBootstrapInput.scala.html经纱@elements.input<div>块)

但我不知道如何在不感染其他"文本字段"的情况下修改模板?

我应该定义另一个implicitFieldConstructor吗?或者做点什么?

我找不到一个如何解决这个问题的例子......

所有自定义模板文档都太罕见了......

有人能举个例子吗?谢谢 !

这是我的代码(播放2.1):

@import views.html.helper.FieldConstructor
@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.f) }

@helper.inputRadioGroup(consultForm("currency") 
  , options = Seq(
    "USD" -> "USD" 
  , "HKD" -> "HKD" 
  , "RMB" -> "RMB") 
  , '_label -> "Currency" 
  , '_error -> consultForm("currency").error.map(_.withMessage("select currency"))
)
Run Code Online (Sandbox Code Playgroud)

======== 4月/ 11更新==============

谢谢@Schleichardt给了我第一步.我追加(FieldConstructor(twitterBootstrapRadioGroup.f) , lang)inputRadioGroup,似乎工作.但是,即使我@elements.input在模板中编写最简单的(没有其他装饰),它仍然垂直跨越.如下截图:

在此输入图像描述

输出html源代码是:

在此输入图像描述

如何修改<span class="buttonset" ...>块?我不应该打电话@elements.input给模板吗?

playframework playframework-2.0 playframework-2.1

3
推荐指数
1
解决办法
1952
查看次数

播放2.0.4 Catch-all路线总是命中

在我的路由文件的末尾,我放置了一个catch-all路由来捕获之前未捕获的请求并将其传递给我自己的路由器(以进行进一步处理):

GET    /*nameUrl      controllers.Application.router(nameUrl: String)
Run Code Online (Sandbox Code Playgroud)

当然,在该行之前还有许多其他路线.对我来说最大的惊喜是,包罗万象的是hitten每一次,即使先前的路线hitten一样,所以如果我打开地址domain.tld/test则显示了我两个日志在控制台Test action hit!Custom router hit!.有一个简化的样本:

public static Result test() {
    Logger.debug("Test action hit!");
    return ok();
}

public static Result router(String nameUrl) {
    Logger.debug("Custom router hit!");
    return ok();
}
Run Code Online (Sandbox Code Playgroud)

路线(按此顺序)

GET    /test          controllers.Application.test
GET    /*nameUrl      controllers.Application.router(nameUrl: String)
Run Code Online (Sandbox Code Playgroud)

我想得到什么:

我想用我的路由器获取文章的url,即domain.tld/category_1/article_title之前没有任何前缀,当然如果我将catch全部更改为稳定的东西,它将不再获得双击:

GET    /news/*nameUrl      controllers.Application.router(nameUrl: String)
domain.tld/news/category_1/article_title
Run Code Online (Sandbox Code Playgroud)

但是我真的想避免/news/细分.那可能吗?

routes playframework playframework-2.0

1
推荐指数
1
解决办法
1196
查看次数