createLink
目的 Purpose
Creates a link that can be used where necessary (for example in an href, JavaScript, Ajax call etc.)使用例 Examples
Example controller for an application called "shop":class BookController { static defaultAction = "list" def list() { [books: Book.list(params)] } def show() { [book: Book.get(params.id)] } }
// generates "/shop/book/show/1" <g:createLink action="show" id="1" />// generates "/shop/book/show?foo=bar&boo=far" <g:createLink action="show" params="[foo: 'bar', boo: 'far']"/>// generates "/shop/book" <g:createLink controller="book" />// generates "/shop/book/list" <g:createLink controller="book" action="list" />// generates "/shop/book/list" <g:createLink url="[action:'list',controller:'book']" />// generates a link tot he book controller in the publishing namespace <g:createLink controller="book" namespace="publishing"/>// generates "http://portal.mygreatsite.com/book" <g:createLink controller="book" absolute="true"/>// generates "http://admin.mygreatsite.com/book" <g:createLink controller="book" base="http://admin.mygreatsite.com"/>// generates "/shop/book/list/1?title=The+Shining&author=Stephen+King" <g:createLink controller="book" action="list" params="[title: 'The Shining', author: 'Stephen King', id: '1']"/>
<a href="${createLink(action: 'list')}">my link</a>
<a href="/shop/book/list">my link</a>
詳細 Description
属性 Attributes
action
(optional) - The name of the action to use in the link; if not specified the default action will be linkedcontroller
(optional) - The name of the controller to use in the link; if not specified the current controller will be linkednamespace
(optional) - the namespace of the controller to use in the linkplugin
(optional) - the name of the plugin which provides the controllerid
(optional) - The id to use in the linkfragment
(optional) - The link fragment (often called anchor tag) to usemapping
(optional) - The named URL mapping to use to rewrite the linkparams
(optional) - A Map of request parametersurl
(optional) - A Map containing the action,controller,id etc.absolute
(optional) - Iftrue
will prefix the link target address with the value of thegrails.serverURL
property fromConfig.groovy
, or http://localhost:<port> if there is no setting inConfig.groovy
and not running in production.base
(optional) - Sets the prefix to be added to the link target address, typically an absolute server URL. This overrides the behaviour of theabsolute
property if both are specified.event
(optional) - The name of a Webflow event to trigger for the flow associated with the givenaction
. Requires the Webflow plugin.