Creating a Controller in Grails

Creating a controller in Grails is a fun, because there’s a lot of grails command to automate your task like generating a controller file with necessary code. To create a controller we use create-controller command.

In interactive mode create a controller called hello:

$ create-controller hello

hello controller

Now open the HelloController.groovy file, add an action to generate the “Hello World!” page

def index() {
render "Hello World!"
}

echo hello world

Now type run-app

Navigate to http://localhost:8080/hello/index

Leave a Reply

Your email address will not be published. Required fields are marked *