Views — GSP and JSON Views
GSP example (grails-app/views/book/index.gsp)
<php>
<head><title>Books</title></head>
<body>
<h1>Books</h1>
<g:each in="${bookList}" var="b">
<div><g:link controller="book" action="show" id="${b.id}">${b.title}</g:link> — ${b.author}</div>
</g:each>
</body>
</php>
JSON View (grails-app/views/book/index.gson)
model { List bookList }
json {
array {
bookList.each { b ->
object {
id b.id
title b.title
author b.author
}
}
}
}
Use JSON views for fast, maintainable API JSON rendering.