试图从HQL查询创建一个对象,但只是无法弄清楚我做错了什么.
查询:
String query = "SELECT product.code, SUM(product.price), COUNT(product.code)
from Product AS product
GROUP BY product.code"
Run Code Online (Sandbox Code Playgroud)
(或者我应该使用新的MyCustomList(product.code,SUM(...,即使它没有映射?)现在我想将这个返回的列表转换为类似的对象:
class MyCustomList{
public String code;
public BigDecimal price;
public int total;
// Constructor
public MyCustomList(String code, String price, int total){ //...
Run Code Online (Sandbox Code Playgroud)
检索数据:
// This throws ClassCastException
List<MyCustomList> list = MyClass.find(query).fetch();
Run Code Online (Sandbox Code Playgroud)
使用Play框架
我正在使用Jackson构建自定义JSON对象.这是正确的方法吗?
它似乎工作得很好(输出是正确的)但我可能会错过我使用JsonNodeFactory的方式.对象是否意味着像我在这里所做的那样传递?
JsonNodeFactory factory = JsonNodeFactory.instance;
ObjectNode dataTable = new ObjectNode(factory);
ArrayNode aaData = new ArrayNode(factory);
for (PkgLoad pkgLoad : pkgLoadList) {
ObjectNode row = new ObjectNode(factory);
row.put("ounces", pkgLoad.ounces);
row.put("revolutions", pkgLoad.revolutions);
aaData.add(row);
}
dataTable.put("aaData", aaData);
Run Code Online (Sandbox Code Playgroud) 我知道现在玩!发布有一个Bootstrap 1.4的帮手.如果我想使用当前版本的Bootstrap,我该怎么办?
playframework twitter-bootstrap playframework-2.0 twitter-bootstrap-2
我在这里使用sbt .13.
到目前为止我有这个:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appVersion = "1.0"
resolvers += "local maven" at "/Users/blankman/.m2/repository/"
val commonDependencies = Seq()
val modelDependencies = Seq(
"com.typesafe.slick" %% "slick" % "2.0.1",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
val serviceDependencies = Seq(
"com.typesafe.slick" %% "slick" % "2.0.1",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
val webDependencies = Seq(
//"org.apache.tomcat" % "tomcat-jdbc" % "8.0.3",
"mysql" % "mysql-connector-java" % "5.1.30",
"com.typesafe.slick" %% "slick" % "2.0.1"
)
lazy val …Run Code Online (Sandbox Code Playgroud) 如何执行上下文
import scala.concurrent.ExecutionContext.Implicits.global
Run Code Online (Sandbox Code Playgroud)
与Play的执行上下文不同:
import play.core.Execution.Implicits.{internalContext, defaultContext}
Run Code Online (Sandbox Code Playgroud) 我一直在玩Play!框架为斯卡拉现在将近一年.我目前正在使用2.5.x版.
我知道Play中控制器的发展以及开发人员如何被迫远离静态object路由.
我也知道Guice在游戏中的用法.
如果您下载激活器并运行:
activator new my-test-app play-scala
Run Code Online (Sandbox Code Playgroud)
Activator将为您生成模板项目.我的问题是围绕该模板的这个文件.
我的测试,应用程序/应用程序/服务/ Counter.scala
package services
import java.util.concurrent.atomic.AtomicInteger
import javax.inject._
/**
* This trait demonstrates how to create a component that is injected
* into a controller. The trait represents a counter that returns a
* incremented number each time it is called.
*/
trait Counter {
def nextCount(): Int
}
/**
* This class is a …Run Code Online (Sandbox Code Playgroud) 我正在评估Play!我公司的框架.我们实际上正在考虑将它用作春天的小兄弟(主要用于"小型企业项目").到目前为止,我们在那里使用Grails,但是由于它与maven的不良集成以及由此产生的动态性质的许多奇怪效果而相当恼火.
但是,我无法从使用Play 实际创建项目的人那里找到任何文章!(我知道,在网站上,他们会告诉你一些使用它的网站,但这并没有真正帮助).
有没有人真正看过一篇描述它如何使用Play的文章!作为应用框架?
我已经阅读了很多关于类型安全激活器的文章,包括最近的Reactive宣言,但我仍然不清楚类型安全激活器和Playframework之间的主要区别.任何使用过两者的人都可以为我总结一下吗?
顺便说一句 - 我知道类型安全激活器更像堆栈而不是Play!这只是webframework,但我只是从webframework的角度看待差异,因为我不打算在堆栈中使用其他项目.
鉴于以下列举......
object MyEnum extends Enumeration {
type MyEnum = Value
val Val1 = Value("val1")
val Val2 = Value("val2")
val ValN = Value("valN")
implicit val myEnumFormat = new Format[MyEnum] {
def reads(json: JsValue) = MyEnum.withName(json.as[String].value) // doesn't compile
def writes(myEnum: MyEnum) = JsString(myEnum.toString)
}
}
Run Code Online (Sandbox Code Playgroud)
...我需要将它序列化/反序列化为JSON.myEnumFormat不编译,我总是收到以下错误消息:
type mismatch;
[error] found : models.MyEnum.Value
[error] required: play.api.libs.json.JsResult[models.MyEnumValue]
[error] Note: implicit value myEnumFormat is not applicable here because it comes after the application point and it lacks an explicit result type
[error] …Run Code Online (Sandbox Code Playgroud) 当我在Play控制台中编译scala时,我得到了这个:
[warn] there were 1 feature warning(s); re-run with -feature for details
[warn] one warning found
Run Code Online (Sandbox Code Playgroud)
我认为这意味着compile -feature,但我得到了这个:
[error] Expected ID character
[error] Not a valid command: compile (similar: completions)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Expected '::'
[error] Expected end of input.
[error] compile -feature
[error]
Run Code Online (Sandbox Code Playgroud)
然后我跑play -feature,我得到了这个:
[warn] The `-` command is deprecated in favor of `onFailure` and will be removed in …Run Code Online (Sandbox Code Playgroud)