我最近正在研究grails,我想知道如何做更复杂的脚手架。
例如,如果我想建立一个类
class Book{
Author a
Publisher p
// ....
}作者班
class Author{
String firstName
String lastName
// ...
}出版者类
class Publisher{
String name
String address
// ....
}如果我有一个BookController
class BookController{
static scaffold = true;
}我有一个布局
作者
但是,如果我希望使用
AuthorID适配适配容忍度适配机AuthorFirstName适配机
我已经查看了http://grails.org/doc/latest/guide/scaffolding.html,但是,我无法将它设置为给定的属性。我想知道我能不能做到这一点?一个教程将是有帮助的。
发布于 2014-08-25 12:40:56
Grails中的脚手架插件并不是专为处理这些复杂视图而设计的。你有几个选择:
install-templates命令并修改脚手架模板来处理您的需求。Author和Publisher。这将改变脚手架输出,但也会发生更大的变化。我不会使用此选项,除非您了解这将对您的域模型所做的所有更改。在这里提出的三种选择中,我建议第三种,因为处理你问题的范围狭窄是最有意义的。
发布于 2014-08-25 14:10:01
你也可以使用瞬变。但在默认情况下不显示瞬变。
您需要使用约束(即id )显式隐藏否则隐藏的字段( modify the templates )。
注:以下代码未经测试,仅供参考。
//optional, but allows code completion in IDE ;-P
String authorName
String getAuthorName(){
return a.firstName + ' ' + a.lastName
}
static transients = [authorName:String]
static constraints = {
id(display:false)
}https://stackoverflow.com/questions/25486106
复制相似问题