registrationcontroller.groovy

来自「grails用户使用指南」· GROOVY 代码 · 共 82 行

GROOVY
82
字号
            class RegistrationController {    def index = { redirect(action:list,params:params) }    // the delete, save and update actions only    // accept POST requests    def allowedMethods = [delete:'POST',                          save:'POST',                          update:'POST']    def list = {        if(!params.max)params.max = 10        [ registrationList: Registration.list( params ) ]    }    def show = {        [ registration : Registration.get( params.id ) ]    }    def delete = {        def registration = Registration.get( params.id )        if(registration) {            registration.delete()            flash.message = "Registration ${params.id} deleted."            redirect(action:list)        }        else {            flash.message = "Registration not found with id ${params.id}"            redirect(action:list)        }    }    def edit = {        def registration = Registration.get( params.id )        if(!registration) {                flash.message = "Registration not found with id ${params.id}"                redirect(action:list)        }        else {            return [ registration : registration ]        }    }    def update = {        def registration = Registration.get( params.id )        if(registration) {             registration.properties = params            if(registration.save()) {                flash.message = "${params.name} updated."                redirect(action:show,id:registration.id)            }            else {                render(view:'edit',model:[registration:registration])            }        }        else {            flash.message = "Registration not found with id ${params.id}"            redirect(action:edit,id:params.id)        }    }    def create = {        def registration = new Registration()        registration.properties = params        return ['registration':registration]    }    def save = {        def registration = new Registration()        registration.properties = params        if(registration.save()) {            flash.message = "${params.name} saved."             redirect(action:show,id:registration.id)        }        else {            render(view:'create',model:[registration:registration])        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?