加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Grails控制器中使用Groovy特征

发布时间:2020-12-14 16:33:22 所属栏目:大数据 来源:网络整理
导读:我想在Grails控制器中使用Groovy特性,如下所示: trait ColumnSelectionController { def selectColumns() { //Do something here }}class MyController implements ColumnSelectionController { def index() { //Calculate list model }} 然而,当我在Grails
我想在Grails控制器中使用Groovy特性,如下所示:

trait ColumnSelectionController {
    def selectColumns() {
        //Do something here
    }
}

class MyController implements ColumnSelectionController {
    def index() {
        //Calculate list model
    }
}

然而,当我在Grails中运行它时,“selectColumns”操作不可见,我从Grails得到404响应.我怀疑我需要对特征做些什么,以便在其中定义的方法被识别为实现类中的动作.谁知道那可能是什么?

编辑1:

更多信息:特征是在src / groovy中定义的,而不是在grails-app / controllers中定义,因此它没有被定义为Artefact.

编辑2:

此外,如果我将特征更改为类,使用@Artefact注释标记它并更改MyController以扩展此类,一切都按预期工作.试图在特征上使用@Artefact注释没有任何意义(没什么大惊喜).

解决方法

只需在trait中定义方法定义@Action注释,这将使此方法作为控制器的Action(当特征实现时)

import grails.web.Action

trait ColumnSelectionController {

  @Action
  def selectColumns() {
     //Do something here
  }
}

希望这可以帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读