无法在 Play 2.5 (Scala) 中流式传输简单字符串
Cannot stream simple string in Play 2.5 (Scala)
我真的很难在 Play 2.5 中传输一个简单的字符串。所以如果我想输出字符串 "Hello" 我可能会这样开始:
package controllers
import javax.inject.Inject
import play.api.mvc.{Action, Controller}
import akka.stream.scaladsl.Source
class Enum @Inject() extends Controller {
def index = Action {
Ok.chunked(Source("hello"))
}
}
但显然这不能编译。我已阅读 Play documentation regarding streaming and I know that in previous versions Ok.chunked(Enumerator("hello"))
would have been the way. And unfortunately Play's migration guide 并没有向我澄清任何这些。可能我看这个画面太久了。
问题是 Source("hello")
是 Char
的来源,因为 Source()
需要 Seq
.
由于 Char
不是 Writeable
(在 play.api.http.Writeable
的意义上),您不能将 Char
的来源提供给 Ok.chunked
如果你只想发送一个 String
元素,你应该 Source.single("hello")
我真的很难在 Play 2.5 中传输一个简单的字符串。所以如果我想输出字符串 "Hello" 我可能会这样开始:
package controllers
import javax.inject.Inject
import play.api.mvc.{Action, Controller}
import akka.stream.scaladsl.Source
class Enum @Inject() extends Controller {
def index = Action {
Ok.chunked(Source("hello"))
}
}
但显然这不能编译。我已阅读 Play documentation regarding streaming and I know that in previous versions Ok.chunked(Enumerator("hello"))
would have been the way. And unfortunately Play's migration guide 并没有向我澄清任何这些。可能我看这个画面太久了。
问题是 Source("hello")
是 Char
的来源,因为 Source()
需要 Seq
.
由于 Char
不是 Writeable
(在 play.api.http.Writeable
的意义上),您不能将 Char
的来源提供给 Ok.chunked
如果你只想发送一个 String
元素,你应该 Source.single("hello")