Korean Views and Layouts

Last updated by admin 3 years ago

?? ????

????? ?

Grails? JavaServer Pages (JSP) ?? Groovy Server Pages (GSP)? ??? ? ??? ?????. ?????? ? ? ?????. ?? ???? ?????(scriptlet) ??? ??? ??? ?? Groovy? ????? ????! Grails ????? ??(convention mechanism)? ???? ???? ??? ??? ?? ?????. ?? ?? "list"?? ??? ??? "list" ?? ?????:

class BookController {
      def 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>

???? ????

????? SiteMesh ? ???? ?? ? ????. ????? ??? ???? ? ??? ????. ???? "layout" ?? ??? ??? ???? ???? ?????:

<html>
    <head>
  <meta name="layout" content="main"></meta>
    </head>
    <body>This is my content!</body>
</html>
?? "main.gsp"?? ???? ???? ???? ???? "grails-app/views/layouts" ????? ???? ???!:
<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 ?? ? ????.

??? ?? ????

????? ???? ??? ??? "??? ?? ????(layout by convention)" ???. ?? ??, ??? ?? ???? ? ?? ?:

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

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

? ???? ??? ?? ?????, ??? ??? ???? ??? ????? ? ?? ????? ?? ???.