Controller Usage

A controller fulfills the C in the Model View Controller (MVC) pattern and is responsible for handling web requests. In Grails a controller is a class that ends in the convention "Controller" and lives in the grails-app/controllers directory. A controller can be created with the create-controller command:

grails create-controller hello

Or via your favourite IDE or text editor.

class HelloController {
	def world = {
		render "Hello World!"

Each action in the controller is a callable block (for example the world action above) that has access to a number of implicit variables and methods which are covered in this reference documentation.

Refer to the user guide topic on Controllers for more information.