0

我需要在运行时添加一个控制器操作。在插件中,我使用 doWithDynamicMethods 添加了一个动态方法,但我不能作为操作调用。

我尝试使用mixin,但它不起作用。@grails.web.Mixin 有一个错误,对我来说没用。而且我不确定我是否可以将其称为一项行动。

我知道我需要将@Action 注释添加到我在 doWithDynamicMethods 中动态创建的方法中。

我应该使用 AstTransformation。或者我想念什么

4

1 回答 1

1

I need to add a controller action on runtime.

No, you don't. You've got some other problem, and you think you can solve it by adding a controller action during runtime. But as you've learned, adding controller actions during runtime is really hard. You should solve your problem in some other way.

I don't know what your problem is, so I can't be too specific. But here's a generically useful trick. In UrlMappings.groovy, you can do this:

"awesome/$stuff"(controller: 'awesome', action: 'doStuff')

And then in AwesomeController.groovy:

public doStuff(String stuff) {
  // whatever arbitrary dynamic dispatch logic you want goes here
}

Hope that helps.

于 2013-11-15T17:00:26.160 回答