如何仅计算grails中的网址(不包含<a> tag)?

时间:2016-01-22 19:10:48

标签: java grails web-applications gsp grails-3.0

If I write

<g:link controller="book" action="list">Book List</g:link>

in GSP it will render to something like

<a href="/book/list">Book List</a>

in HTML.

But what if I wish to call this URL with AJAX? I don't need <a> tag anymore, I need only url /book/list.

How to compute it?

Note that it should depends on application context, trailing slash etc.

1 个答案:

答案 0 :(得分:2)

请改用createLink,这是doc

一些例子:

 // 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']" />