h4. Available Scopes
h4.可用范围(Scopes)
Scopes are essentially hash like objects that allow you to store variables. The following scopes are available to controllers:
范围(Scopes)本质上就像hash对象,允许你存储变量。下列为controllers(控制器)可用范围(Scopes):
* [servletContext|controllers] - Also known as application scope, this scope allows you to share state across the entire web application. The servletContext is an instance of [javax.servlet.ServletContext|api:javax.servlet.ServletContext]
* [servletContext|controllers] - 也被叫做应用(application)范围, 这个范围允许你横跨整个web应用程序共享状态. servletContext对象为一个[javax.servlet.ServletContext|api:javax.servlet.ServletContext]实体。
* [session|controllers] - The session allows associating state with a given user and typically uses cookies to associate a session with a client. The session object is an instance of [HttpSession|api:javax.servlet.http.HttpSession]
* [session|controllers] - session允许关联某个给定用户的状态,通常使用Cookie把一个session与一位客户关联起来 ,session对象为一个[HttpSession|api:javax.servlet.http.HttpSession]实体
* [request|controllers] - The request object allows the storage of objects for the current request only. The request object is an instance of [HttpServletRequest|api:javax.servlet.http.HttpServletRequest]
* [request|controllers] - request对象只允许存储当前的请求(request)对象,request 对象为一个[HttpServletRequest|api:javax.servlet.http.HttpServletRequest]实体
* [params|controllers] - Mutable map of incoming request (CGI) parameters
* [params|controllers] - 可变的进入请求参数map(map为java.util.Map类型参数)。
* [flash|controllers] - See below.
* [flash|controllers] - 见下文.
h4. Accessing Scopes
h4. 存取范围(Scopes)
Scopes can be accessed using the variable names above in combination with Groovy's array index operator even on classes provided by the Servlet API such as the [HttpServletRequest|api:javax.servlet.http.HttpServletRequest]:
Scopes的存取可以通过使用上面变量名与Groovy 的array索引操作符的结合来访问,甚至可以使用Servlet API提供的类,例如HttpServletRequest : [HttpServletRequest|api:javax.servlet.http.HttpServletRequest]:
{code:java}
class BookController {
def find = {
def findBy = params["findBy"]
def appContext = request["foo"]
def loggedUser = session["logged_user"]
}
}
{code}
You can even access values within scopes using the de-reference operator making the syntax even clearer:
你甚至可以使用.操作符来存取范围(Scopes)内部值,这样使语法更加简洁清楚:
{code:java}
class BookController {
def find = {
def findBy = params.findBy
def appContext = request.foo
def loggedUser = session.logged_user
}
}
{code}
This is one of the ways that Grails unifies access to the different scopes.
这是统一存取不同范围的方式之一.
h4. Using Flash Scope
h4. 使用 Flash Scope
Grails supports the concept of [flash|controllers] scope is a temporary store for attributes which need to be available for this request and the next request only. Afterwards the attributes are cleared. This is useful for setting a message directly before redirection, for example:
Grails 支持[flash|controllers] scope的概念,它临时存贮只在这次请求和下次请求中使用的属性,随后属性值将被清除。这在重定向之前直接设置消息是非常有用的。
{code:java}
def delete = {
def b = Book.get( params.id )
if(!b) {
flash.message = "User not found for id ${params.id}"
redirect(action:list)
}
... // remaining code
}
{code}
分享到:
相关推荐
LED Player6.1.2 Setup
jetty-6.1.2rc2.zip jetty-6.1.2rc2.zipjetty-6.1.2rc2.zipjetty-6.1.2rc2.zipjetty-6.1.2rc2.zip
6.1.2shsh
shsh 6.1.2
ios6.1.2完美越狱工具,系统要求windows
资源关闭了00000113F40A650A_6.1.2-10B146_cydia
免费下载 gmp-6.1.2.tar.xz_FreeDownload.zip 文件后,解压此文件即可得到 gmp-6.1.2.tar.xz 源文件。
iphone4s 6.1.2SHSH私人珍藏,希望不嫌弃
前端有名字体图标库 FontAwesome Por 6.1.2版本,包含web和desktop 文件所以有点大
ios6.1.2shsh备份下载
欢迎下载 IPHONE4 6.1.2 SHSH
torque 6.1.2 for Linux ,HPC作业调度软件,建议与maui配合使用。
1625464114712700_unc0ver_Release_6.1.2.ipa
IPHONE4 6.1.2 SHSH iphone4 验证 shsh文件
Elasticsearch6.1.2 Java客户端,使用meven仓库创建,配置后即可使用。
完整的qwt6.1.2文件(含qwt-6.1.2和qwt-6.1.2.qch)及亲测可用的安装方法qwt6.1.2_qt5.6.0_win7_win10
torque-6.1.2.tar.gz版本,用于torque作业提交系统下载应用
gmp-6.1.2 源码代码 gcc 升级 自己备用
iPhone3,1_SHSH_6.1.2
VirtualDJ_6.1.2_pro汉化破解版