📄 varref.html
字号:
<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Variable References</title><link href="../docbook.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.65.0" name="generator"><link rel="home" href="index.html" title="OGNL Language Guide"><link rel="up" href="basicExpressions.html" title="Chapter 4. Expressions"><link rel="previous" href="methods.html" title="Calling Methods"><link rel="next" href="paren.html" title="Parenthetical Expressions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Variable References</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="methods.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><th align="center" width="60%">Chapter 4. Expressions</th><td align="right" width="20%"> <a accesskey="n" href="paren.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="varref"></a>Variable References</h2></div></div><div></div></div><p><span class="acronym">OGNL</span> has a simple variable scheme, which lets you store intermediate results and use them again, or just name things to make an expression easier to understand. All variables in <span class="acronym">OGNL</span> are global
to the entire expression. You refer to a variable using a number sign in front of its name, like this:</p><pre class="programlisting">#var</pre><p><span class="acronym">OGNL</span> also stores the current object at every point in the evaluation of an expression in the this variable, where it can be referred to like any other variable. For example, the following expression operates on
the number of listeners, returning twice the number if it is more than 100, or 20 more than the number otherwise:</p><pre class="programlisting">listeners.size().(#this > 100? 2*#this : 20+#this)</pre><p><span class="acronym">OGNL</span> can be invoked with a map that defines initial values for variables. The standard way of invoking <span class="acronym">OGNL</span> defines the variables <tt class="varname">root</tt> (which holds the initial, or root,
object), and <tt class="varname">context</tt> (which holds the <tt class="classname">Map</tt> of variables itself).</p><p>To assign a value to a variable explicitly, simply write an assignment statement with a variable reference on the left-hand side:</p><pre class="programlisting">#var = 99</pre></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="methods.html"><img src="../images/navigation/prev.gif" alt="Prev"></a> </td><td align="center" width="20%"><a accesskey="u" href="basicExpressions.html"><img src="../images/navigation/up.gif" alt="Up"></a></td><td align="right" width="40%"> <a accesskey="n" href="paren.html"><img src="../images/navigation/next.gif" alt="Next"></a></td></tr><tr><td valign="top" align="left" width="40%">Calling Methods </td><td align="center" width="20%"><a accesskey="h" href="index.html"><img src="../images/navigation/home.gif" alt="Home"></a></td><td valign="top" align="right" width="40%"> Parenthetical Expressions</td></tr></table></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -