Grails 脚手架显示的列数少于域

发布于 2025-01-04 04:54:35 字数 684 浏览 1 评论 0原文

我的域类中有 6 列。但当脚手架设置为 true 时,我在控制器列表上只看到 5 列。 我的数据库是mySql。当使用正确的列数创建执行表时 我的域类

class RouteDesc {
String routenumber
String routeoperator
String routeinstructions
Date validfrom
Date validto
String weekendavailablity

static constraints = {
    routenumber blank:false, unique:true,  display:true
    routeoperator blank:false,  display:true
    routeinstructions blank:true,  display:true
    validfrom display:true
    validto display:true
    weekendavailablity display:true
}
//static belongs to = RouteId

String toString () {
    return routenumber
}
}

我的控制器类

class RouteDescController {

  static scaffold = true
}

I have 6 columns in my domain class. But i only see 5 columns on the controller list when scaffold is set to true.
My database is mySql. When executed table is created with correct number of columns
My domain class

class RouteDesc {
String routenumber
String routeoperator
String routeinstructions
Date validfrom
Date validto
String weekendavailablity

static constraints = {
    routenumber blank:false, unique:true,  display:true
    routeoperator blank:false,  display:true
    routeinstructions blank:true,  display:true
    validfrom display:true
    validto display:true
    weekendavailablity display:true
}
//static belongs to = RouteId

String toString () {
    return routenumber
}
}

My Controller class

class RouteDescController {

  static scaffold = true
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拒绝两难 2025-01-11 04:54:35

默认的脚手架列表页面将列数限制为 6(因为eachWithIndex 是从零开始的),其中 1 个将用于 ID 列,因此仅显示 5 个属性。如果您想更改此设置,可以通过 grails install-templates 安装模板(在 Grails 2.0 中),该模板会将模板放置在 src/templates/scaffolding/ 下。您需要更新的模板是 list.gsp,大约中间有以下代码:

...
props.eachWithIndex { p, i ->
    if (i < 6) {
       ...
    }
}

您需要将 6 更改为您想要的任何内容。附带说明一下,字段通过脚手架出现的顺序可以通过它们在约束中定义的顺序来控制( http://grails.org/doc/latest/guide/scaffolding.html)。

The default scaffolding list page limits the number of columns to 6 (since eachWithIndex is zero based) and 1 of them will be used for the ID column so only 5 attributes will show. If you'd like to change this you can install templates via grails install-templates which (in Grails 2.0) will place the templates under src/templates/scaffolding/. The template you'd need to update is the list.gsp about half way down there is the following code:

...
props.eachWithIndex { p, i ->
    if (i < 6) {
       ...
    }
}

You'd need to change that 6 to whatever you want it to be. As a side note the order that fields appear through scaffolding can be controlled by the order in which they are defined in the constraints ( http://grails.org/doc/latest/guide/scaffolding.html).

屋顶上的小猫咪 2025-01-11 04:54:35

贾里德·奥尔森建议的又一补充

props.eachWithIndex { p, i ->
  if (i < 6) {
   ...
  }

}

也改变

<td><g:link action="show" id="\${${propertyName}.id}">\${fieldValue(bean: ${propertyName}, field: "${p.name}")}</g:link></td>
                    <%      } else if (i < 6) {
                                if (p.type == Boolean.class || p.type == boolean.class) { %>
                        <td><g:formatBoolean boolean="\${${propertyName}.${p.name}}" />
</td>

One more addition to what Jarred Olson suggested

props.eachWithIndex { p, i ->
  if (i < 6) {
   ...
  }

}

Also change

<td><g:link action="show" id="\${${propertyName}.id}">\${fieldValue(bean: ${propertyName}, field: "${p.name}")}</g:link></td>
                    <%      } else if (i < 6) {
                                if (p.type == Boolean.class || p.type == boolean.class) { %>
                        <td><g:formatBoolean boolean="\${${propertyName}.${p.name}}" />
</td>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文