3

请参阅:Java(任何框架)中是否有 CRUD 生成器实用程序,例如 Rails 中的脚手架?

我有同样的问题,但关于 Scala。我知道 Play framework 1.x 有生成器,但 2.x 删除了它们,是否有任何基于 Scala 的 Web 框架的工作 CRUD / Scaffolding 生成器?

4

2 回答 2

2

我也在寻找一个脚手架工具(它弹出了你的问题)并找到了这个:http ://skinny-framework.org/documentation/scaffolding.html

还没有尝试过,但是文档看起来可以完成这项工作:

./skinny g model tweet userId:Long text:String user:Option[User] 将创建

package model

import skinny.orm._, feature._
import scalikejdbc._
import org.joda.time._

// If your model has +23 fields, switch this to normal class and mixin scalikejdbc.EntityEquality.
case class Tweet(
  id: Long,
  userId: Long,
  text: String,
  user: Option[User] = None,
  createdAt: DateTime,
  updatedAt: DateTime
)

object Tweet extends SkinnyCRUDMapper[Tweet] with TimestampsFeature[Tweet] {

  override lazy val defaultAlias = createAlias("t")

  lazy val userRef = belongsTo[User](User, (t, u) => t.copy(user = u))

  /*
   * If you're familiar with ScalikeJDBC/Skinny ORM, using #autoConstruct makes your mapper simpler.
   * (e.g.)
   * override def extract(rs: WrappedResultSet, rn: ResultName[Tweet]) = autoConstruct(rs, rn)
   *
   * Be aware of excluding associations like this:
   * (e.g.)
   * case class Member(id: Long, companyId: Long, company: Option[Company] = None)
   * object Member extends SkinnyCRUDMapper[Member] {
   *   override def extract(rs: WrappedResultSet, rn: ResultName[Member]) =
   *     autoConstruct(rs, rn, "company") // "company" will be skipped
   * }
   */
  override def extract(rs: WrappedResultSet, rn: ResultName[Tweet]): Tweet = new Tweet(
    id = rs.get(rn.id),
    userId = rs.get(rn.userId),
    text = rs.get(rn.text),
    createdAt = rs.get(rn.createdAt),
    updatedAt = rs.get(rn.updatedAt)
  )
}

希望这可以帮助!

于 2016-05-26T15:08:40.397 回答
1

Copying the answer from the comments in order to remove this question from the "Unanswered" filter:

No, was some talk on the play user group about this, nothing planned. Twitter Bootstrap + DAO implementation + RESTful routing is your best bet; i.e. roll your own.

...

Check the docs on integrating TB [Twitter Bootstrap], pretty awesome, gives you a great headstart, CRUD with Play is fairly easy.

~ answer per virtualeyes

于 2013-10-09T04:56:29.720 回答