【问题标题】:Grails Where is the index() function in a controller get called?Grails 控制器中的 index() 函数在哪里被调用?
【发布时间】:2016-05-26 08:41:46
【问题描述】:

在一个 grails 项目中,我有一个名为 LineLeaderController.groovy 的文件。它里面有一个类似下面的函数,它返回一个地图。

def index() {
  Map allData = [:]
  // more code here
  return allData
}

我如何知道哪个文件正在调用这个函数 index()? 当我尝试调试时,在此函数运行后,allData 被填充到名为 _tool_preview.gsp 的 gsp 文件中。我什至尝试在整个项目中搜索这个关键字 index() 函数,但我没有找到任何相关结果。请帮忙。

【问题讨论】:

    标签: grails gsp


    【解决方案1】:

    索引操作是控制器的默认操作。例如,假设以下控制器处理与模式 /foo/* 匹配的所有 URL

    class FooController {    
      def index() {}
      def bar() {}
    }
    

    如果向/foo/bar 发出请求,它将调用bar 操作,但如果仅向/foo/ 发出请求,则将调用index,因为它是默认操作。尾部反斜杠是可选的,因此index 也将处理对/foo 的请求。

    以上假设您使用的是默认 URL 映射。在您的应用程序中,这些可能会在文件 grails-app/conf/UrlMappings.groovy 中被覆盖。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      • 2014-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多