NEO

蜀道难,难于上青天!

导航

Grails指南摘要-403-生命周期

Posted on 2013-06-04 23:20  页面载入出错  阅读(335)  评论(0编辑  收藏  举报

1.理解Flash Scope

// 存储一个消息在flash范围
fash.message = 'I am available next time you request me!'

当这个消息被下一个消息覆盖时就自动销毁

2.访问请求参数

def userName = request.getParameter('userName')
log.info("User Name: ${userName}")

简单写法

def userName = params.userName
log.info("User Name: ${userName}")

3.请求参数的类型转换

def index() {
    // since params.counter is a string, it must be converted to an int if
    // the application intends to use the value as a number
    def counter = params.counter.toInteger()
    //
}

使用int类型转换

def index() {
    def counter = params.int('counter')
    //
}

使用list类型转换

def index() {
    for (name in params.list('name') {
        // do something with name
    }
}