Chinese Views and Layouts

Last updated by admin 3 years ago

???????

??????

Grails ????JSP?JavaServer Pages???GSP?Groovy Server Pages?????????????????????????GSP??scriptlet???Groovy?????Java! Grails ??? ??????????????????????? list ??????????"list" ???:

class BookController {
      @Property list = {
         ["books" : Book.list() ]
      }
}
?????????????? "grails-app/views/book" ??????????"list.jsp" ? "list.gsp". ?????GSP???:
<html>
<head>
    <title>Book list</title>
</head>
<body>
<h1>Book list</h1>
<table>
    <tr>
        <th>Title</th>
         <th>Author</th>
    </tr>

<g:each in="${books}"> <tr> <td>${it.title}</td> <td>${it.author}</td> </tr> </g:each> </table> </body> </html>

???????Layouts?

????????Grails?SiteMesh?????????????????????????????????"layout"?meta?????????????????

<html>
    <head>
  <meta name="layout" content="main"></meta>
    </head>
    <body>This is my content!</body>
</html>
???"grails-app/views/layouts"???????"main.gsp"?????????????
<html>
       <head>
          <title><g:layoutTitle default="An example decorator" /></title>
               <g:layoutHead />
      </head>
 <body onload="${pageProperty(name:'body.onload')}">
                 <div class="menu"><!--my common menu goes here--></menu>
                 <div class="body">
                      <g:layoutBody />
             </div>
 </body>
</html>
??????? GSP ?? ????????????

?????????????

?????????????????????????? ????

class BookController {
    @Property list = {  … }
}
????????? {{grails-app/views/layouts/book.gsp}} ?????????????? {{BookController}} ??????????????

?????????????{{{}grails-app/views/layouts/book/list.gsp}} ?????????????{{{}BookController{}}}?????list?????

??????????????????????????.