<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    asdtiang的博客 感謝blogjava提供的博客交流平臺

    grails 學習記--command-controller

    Posted on 2011-04-29 15:00 asdtiang 閱讀(845) 評論(0)  編輯  收藏
    grails 命令:
    shell
    console   //啟動一個類似groovy 的console,console里可以訪問domain.service等。



    controller里的已有變量(自己不常用的記下,其它的查看文檔,例如request,reponse)

    actionName

    Purpose

    Returns the name of the currently executing action.


    controllerName

    Purpose

    Returns the name of the currently executing controller.

    defaultAction

    Purpose

    Allows you to explicitly specify the default action that should be executed if no action is specified in the URI.

    Examples

    class BookController {
    static defaultAction = "list"
    def list = {
    [books:Book.list()]
    }
    }

    grailsApplication

    Purpose

    An instance of the org.codehaus.groovy.grails.commons.GrailsApplication class.

    Examples

    class BookController {
    def list = {
    def bookClass = grailsApplication.classLoader.loadClass("Book")
    [book:bookClass.newInstance()]
    }
    }

    Description

    The GrailsApplication class provides information about the conventions within Grails and access to metadata, config and the ClassLoader






    servletContext

    Purpose

    The servletContext object is an instance of the Servlet API's ServletContext class.

    Examples

    class BookController {
    def doSomething = {
    def input
    try {
    input = servletContext.getResourceAsStream("/WEB-INF/myscript.groovy")
    def result = new GroovyShell().evaluate(input.text)
    render result
    }
    finally {
    input.close()
    }
    

    } }

    Description

    The Servlet API's ServletContext is useful for, amongst other things, storing global application attributes, reading local server resources and establishing information about the servlet container.







    withForm //防止重復提交表單

    Purpose

    Used to handle duplicate form submissions.

    Examples

    withForm {
    // good request
    }.invalidToken {
    // bad request
    }

    Description

    The withForm method requires the use of the useToken attribute in a form

    <g:form useToken="true" ...>

    Then in your controller code you can use the withForm method to handle valid and invalid requests:

    withForm {
    // good request
    }.invalidToken {
    // bad request
    }





    withFormat

    Purpose

    Used to execute different responses based on the incoming request Accept header, format parameter or URI extension. See content negotiation for more information.

    Examples

    import grails.converters.*
    

    class BookController { def books def list = { this.books = Book.list() withFormat { html bookList:books js { render "alert('hello')" } xml { render books as XML } } } }

    Description

    The withFormat method takes a block within the scope of which you can execute different methods whose names match the content type you want to respond to. For example:

    withFormat {
    html bookList:books
    js { render "alert('hello')" }
    xml { render books as XML }
    }

    Here we invoke three methods called html, js and xml that use mime type names configured in grails-app/conf/Config.groovy (See content negotiation for more information). The call to html accepts a model (a map) which is passed on to the view. Grails will first search for a view called grails-app/views/book/list.html.gsp and if that is not found fallback to grails-app/views/book/list.gsp.

    Note that the order of the types is significant if either the request format is "all" or more than one content type has the same "q" rating in the accept header. In the former case, the first type handler in the block is executed ("html" in the short example above). The latter case is more confusing because it only holds if there is more than one content type with the highest "q" rating for which you have a type handler and you have more than one type handler matching that "q" rating. For example, say the request has "text/html" and "application/xml" with a "q" rating of 1.0, then this code:

    withFormat {
    xml { … }
    html { … }
    }


    天蒼蒼,野茫茫,風吹草底見牛羊

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    posts - 80, comments - 24, trackbacks - 0, articles - 32

    Copyright © asdtiang

    asdtiang的博客 PaidMailz
    點擊廣告網賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
    主站蜘蛛池模板: 亚洲AV成人精品日韩一区| 久久久久亚洲av无码专区| 97久久精品亚洲中文字幕无码| 国产在线观看无码免费视频| 五月婷婷亚洲综合| 黄色网址大全免费| 亚洲av中文无码| 污污的视频在线免费观看| 亚洲AV永久无码精品一区二区国产 | 久久精品国产亚洲| 免费黄网站在线看| 亚洲欧洲免费视频| 成年人视频免费在线观看| 亚洲黄色网址在线观看| 免费在线看v网址| 亚洲精品乱码久久久久久蜜桃图片| 大地资源二在线观看免费高清| 亚洲精品无码日韩国产不卡av| 免费jjzz在线播放国产| 国产乱子伦精品免费视频| 亚洲国产国产综合一区首页| 8x8×在线永久免费视频| 亚洲国产视频久久| 亚洲国产精品综合久久网络| 国产激情久久久久影院老熟女免费| 亚洲熟妇丰满多毛XXXX| 亚洲成人免费网站| 激情婷婷成人亚洲综合| 狠狠亚洲婷婷综合色香五月排名| 老汉精品免费AV在线播放| 亚洲精品福利你懂| 亚洲国产精品一区二区九九 | 免费毛片a线观看| 麻豆狠色伊人亚洲综合网站| 免费国产在线观看| 久久99国产综合精品免费| 亚洲国产成人精品无码区二本 | 国产成人毛片亚洲精品| **一级一级毛片免费观看| 国产精品亚洲一区二区三区在线观看 | 97无码免费人妻超级碰碰夜夜|