直接与GSP联系 [英] link directly to GSP

查看:107
本文介绍了直接与GSP联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在普惠制中,是否可以创建与另一个普惠制的直接联系?我知道我可以使用:

 < g:createLink controller =useraction =foo/> 

并在UserController中定义foo动作以显示相应的GSP

  class UserController {
def foo = {}
}

但是有没有什么办法可以达到同样的结果而不必创建空的 foo 动作?



感谢,
Don

解决方案

createLink标签适用于控制器操作,并且不会按照您希望的url属性。

您可以直接通过 /user/foo.gsp 获得gsp, a href =http://grails.org/doc/latest/ref/Tags/link.html =noreferrer>链接和 resource 标记。

 < g:link url =$ {resource(dir:'user',file:'foo.gsp')}> user / foo.gsp< / g:link> 

另外,您可以创建一个URL映射,将请求直接映射到视图。

  class UrlMappings {
static mappings = {
/ user / foo(view:user / foo)


$ / code>

使用Grails 1.2可以创建一个指定的网址映射即地图直接到一个视图:

  class UrlMappings {
static mappings = {
name userFoo:/ user / foo(view:user / foo)
}
}

然后在链接标记中使用它:

 < link:userFoo> User Foo< / link:userFoo> 

 < g:链接映射=userFoo> User Foo< / g:link> 


In a GSP, is it possible to create a direct link to another GSP? I know I can use:

<g:createLink controller="user" action="foo"/>

and in UserController define the foo action to just show the corresponding GSP

class UserController {
    def foo = {}
}

But is there any way I can achieve the same result without having to create the empty foo action?

Thanks, Don

解决方案

The createLink tag is geared for use with controller actions and won't do what you want it to outside of the url attribute.

You can always get to a gsp by directly: /user/foo.gsp with a combination of the link and resource tags.

<g:link url="${resource(dir:'user', file:'foo.gsp')}">user/foo.gsp</g:link>

Othewise you can create a URL Mapping that maps a request directly to a view.

class UrlMappings {
    static mappings = {
        "/user/foo"(view:"user/foo")
    }
}

Using Grails 1.2 you can create a named URL Mapping that maps directly to a view:

class UrlMappings {
    static mappings = {
        name userFoo: "/user/foo"(view:"user/foo")
    }
}

and then use it with the link tag:

<link:userFoo>User Foo</link:userFoo>

or

<g:link mapping="userFoo">User Foo</g:link>

这篇关于直接与GSP联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆