什么是模板,如何以及在gsp中创建它

  • 本文关键字:gsp 创建 grails
  • 更新时间 :
  • 英文 :


以下是什么是template ?我在哪里创建它以及如何使用它?

def RenderDemo = {
    //Render text to response
    render "hellooooo"
    //Render text for specified content type/ encoding
    render (text: "<strong><h1><marquee>Akshay</marquee></h1></strong>" , contentType: "text/html")
    //Render a Template to the response for the specified model...
    def theShining = [title: "The Shining" , auther : "king"]
    render(template: "RenderDemo" , model: [book : theShining])
}

模板是GSP的一部分或片段。它的目的是被重用。就像任何其他GSP一样,它属于grails-app/views/目录结构。所有模板都有一个以下划线_开头的文件名。因此,在您的示例中模板将是:grails-app/views/render/_renderDemo.gsp .

我强烈建议你阅读关于视图和模板的官方文档,它解释了为什么要使用模板,并为你提供了更多关于模板的一般细节。

最新更新