Differences between action and methods in Grails controllers

后端 未结 3 1665
执笔经年
执笔经年 2021-01-27 04:00

As far as I know, if I want to create an action in a controller then I can do it by:

class My Controller {
    def myAction = {
      println \"in my action \"
          


        
3条回答
  •  一整个雨季
    2021-01-27 04:35

    Leveraging methods instead of actions(Closure properties) has some advantages:

    1. Memory efficient
    2. Allow use of stateless controllers (singleton scope)
    3. You can override actions from subclasses and call the overridden superclass method with super.actionName()
    4. Methods can be intercepted with standard proxying mechanisms, something that is complicated to do with Closures since they're fields.

    Please visit following link for more information.

    Grails controllers

提交回复
热议问题