参见:Is there a CRUD generator utility in Java(any framework) like Scaffolding in Rails?
我有同样的问题,但关于 Scala。我知道 Play 框架 1.x 有生成器,但 2.x 删除了它们,是否有适用于任何基于 Scala 的 Web 框架的有效 CRUD/脚手架生成器?
最佳答案
我也在寻找一个脚手架工具(它弹出了你的问题)并找到了这个:http://skinny-framework.org/documentation/scaffolding.html
我还没有尝试过,但文档看起来可以完成这项工作:
./skinny g 模型 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)
)
}
希望这对您有所帮助!
关于ruby-on-rails - Scala(任何框架)中是否有像 Rails 中的脚手架这样的 CRUD 生成器实用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14649648/