set
目的 Purpose
Sets the value of a variable accessible with the GSP page.使用例 Examples
<g:set var="tomorrow" value="${new Date() + 1}" /><g:set var="counter" value="${1}" /> <g:each in="${list}"> ${counter}. ${it} -> ${counter % 2 == 0 ? 'even' : 'odd'} <g:set var="counter" value="${counter + 1}" /><br/> </g:each>
<g:set var="foo" value="${new Date()}" scope="page" /> <g:set var="bar" value="${new Date() - 7}" scope="session" />
<g:set var="foo">Hello!</g:set>
<g:set var="bookService" bean="bookService"/>
<%@ page import="org.springframework.context.MessageSource" %> <g:set var="messageSource" bean="${MessageSource}"/>
詳細 Description
属性 Attributes
var
- The name of the variablevalue
- The initial valuebean
- The name or the type of a bean in the applicationContext; the type can be an interface or superclassscope
- Scope to set variable in, one ofrequest
,page
,flash
orsession
. Defaults topage
.