Learn GRAILS with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Grails Simple Blog App
// grails-app/controllers/com/example/BlogController.groovy
package com.example
class BlogController {
def index() {
def posts = Post.list()
[posts: posts]
}
def show(Long id) {
def post = Post.get(id)
[post: post]
}
}
// grails-app/domain/com/example/Post.groovy
package com.example
class Post {
String title
String content
}
// grails-app/views/blog/index.gsp
<h1>Blog Posts</h1>
<ul>
<g:each in="${posts}" var="post">
<li><g:link action="show" id="${post.id}">${post.title}</g:link></li>
</g:each>
</ul>
Demonstrates a simple Grails controller and GSP view for listing blog posts using GORM.