【问题标题】:Grails Scaffolding SelectGrails 脚手架选择
【发布时间】:2012-01-21 02:29:07
【问题描述】:

我在使用标签时遇到了性能问题。在数据库中的某些表中,我有数千条记录,当我尝试在 Grails 中编辑某些字段时,标签会生成表中所有记录的下拉列表,这会导致真正的性能问题,有时甚至会出现 EndOfMemorryError。生成的 html 很大,我尝试实现一个自动完成方法来列出,但结果并不令人满意,因为我希望这是我的 300 个 Java 类的全局解决方案,如果我使用自动完成,我必须为它编写我的每一堂课,现在我的想法是尝试使用弹出窗口更改下拉列表,这些弹出窗口使用分页显示记录。我相信我必须在 renderEditor.template 中更改此代码:

    private renderManyToOne(domainClass,property) {
    if (property.association) {
        def sb = new StringBuilder()
        sb << '<g:select'
        // id is "x" and name is "x.id" as the label will have for="x" and "." in an id will confuse CSS
        sb << ' id="' << property.name << '"'
        sb << ' name="' << property.name << '.id"'
        sb << ' from="${' << property.type.name << '.list(max: 10, offset: offset)}"'
        sb << ' optionKey="id"'
        if (isRequired()) sb << ' required=""'
        sb << ' value="${' << "${domainInstance}?.${property.name}" << '?.id}"'
        sb << ' class="many-to-one"'
        sb << renderNoSelection(property)
        sb << '/>'
        sb as String
    }
}

任何想法将不胜感激:)

【问题讨论】:

标签: java hibernate grails select pagination


【解决方案1】:

您可以通过使用 DefautlGrailsDomainClass.getPersistentProperties() 搜索域类中的所有字段来为自动完成创建通用 hql。对于大型数据集,这可能会产生糟糕的性能,但它会足够灵活,因此您不需要触及域的一行,也不需要为每个域编写特定的查询。

使用 grails install-templates 并修改用于脚手架的模板,无需自己破解 grails 代码。

这是文档:http://grails.org/doc/2.0.x/ref/Command%20Line/install-templates.html

【讨论】:

  • 他引用的renderEditor.template模板之一。
  • 我正在修改那些模板,这样就不行了,谢谢:)
猜你喜欢
  • 2011-04-11
  • 1970-01-01
  • 2011-02-13
  • 1970-01-01
  • 1970-01-01
  • 2013-05-10
  • 2012-04-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多