gpt4 book ai didi

grails - 在服务和 Controller Grails之间传递数据

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

我是grails的新手,我不知道该如何解决。我需要将数据从服务类(someserviceclass.groovy)中的方法传递到Grails中的操作 Controller 。我怎样才能做到这一点?

最佳答案

控制者

class MyController {
def myService

def myAction() {
def values = myService.getData()

[viewVarible: values] // since our method return def we don't need to use return keyword
}
}

服务
class MyService {

def getData() {
def data = [:]

data.put("key1", "value1")
data.put("key2", "value2")
data.put("key3", "value3")

return data // we could have just said data without the return keyword
}
}

关于grails - 在服务和 Controller Grails之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43375306/

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