gpt4 book ai didi

grails - 在gsp中调用域方法

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

我在域类中创建了一个名为affichage(s)的方法,该方法可以检索介于<name><adresse>之间的字符串:

enter code here



def affichage(s){

def l=[]
def regex = /\<.\w*.\>/
def matcher = s =~ regex
matcher.each{match ->
l.add(match)}
l.each{
for (i in l){
println i
}}}}

我已经在groovyConsole中运行了此功能,没关系。

如何在gsp中调用此方法以将其应用于文本字段?

最佳答案

为此,您可以将域对象加载到 Controller 中,然后将其传递给 View 。因此,在 Controller 中类似以下内容:

// assuming theDomainObject/anotherObject are loaded, preferably via service calls
render view: 'theView', model: [object: theDomainObject, another: anotherObject]

然后在 View 中您可以执行
${object.yourMethod()}

${another.someprop}

请注意,首先要调用一个方法,接下来要获取属性。还要注意,在括号内,您可以引用在 Controller 中的模型上传递回来的内容。的
${...}

告诉gsp使用传回的模型对象。
像这样,grails很酷。

关于grails - 在gsp中调用域方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6009416/

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