Anatomy of a Grails Controller

Let’s examine the TekEventController first: what is it doing for us, and what else we can do with it? Open TekDays/grails-app/controllers/com/tekdays/TekEventController.groovy, and follow along as we take a look at it in chunks:

beyond.2/TekDays/grails-app/controllers/com/tekdays/TekEventController.groovy
 
package​ com.tekdays
 
 
import​ static org.springframework.http.HttpStatus.*
 
import​ grails.transaction.Transactional
 
 
@Transactional(readOnly = true)
 
class​ TekEventController {
 
 
static​ allowedMethods = [save: ​"POST"​, update: ​"PUT"​, delete: ​"DELETE"​]
 
 
def​ index(​Integer​ max) {
 
params.max = ​Math​.min(max ?: 10, 100)
 
respond TekEvent.list(params),
 
model:[tekEventInstanceCount: TekEvent.count()] ...

Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.