gpt4 book ai didi

grails - Grails模板访问数据库冗余

转载 作者:行者123 更新时间:2023-12-02 14:30:30 24 4
gpt4 key购买 nike

我有一个模板

_template.gsp

<g:each in="${temp}" status="i" var="var">
${var}
</g:each>

我在所有屏幕上渲染此模板,该怎么做?
我这样做了,我发现它很多余

控制者
def action1(){
def temp = Temp.list()
[temp:temp]
}

def action2(){
def temp = Temp.list()
[temp:temp]
}

Action 1.gsp
<g:render template ="../template" />

action2.gsp
<g:render template ="../template" />

最佳答案

使用<g:include>并包括来自各种GSP的结果(仍可以是模板)可能会更好。

例如:

def sharedAction() {
def temp = Temp.list()
render(template: 'templateNameHere', model: [temp: temp])
}
def action1() {
...
}
def action2() {
...
}

action1.gsp和action2.gsp
<g:include controller="theControllerName" action="sharedAction" />

_templateNameHere.gsp
<g:each in="${temp}" status="i" var="var">
${var}
</g:each>

关于grails - Grails模板访问数据库冗余,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33686893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com