直接链接至普惠制
在一个普惠制中,是否可以创建到另一个普惠制的直接链接?我知道我可以使用:
<g:createLink controller="user" action="foo"/>
并在 UserController 中定义 foo 操作来仅显示相应的 GSP
class UserController {
def foo = {}
}
但是有什么方法可以实现相同的结果而不必创建空的 foo 操作?
谢谢, 大学教师
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
createLink 标签 适合与控制器操作一起使用,但不会这样做你想要它在 url 属性之外的内容。
您始终可以通过以下方式直接访问 gsp:
/user/foo.gsp
与 链接 和资源 > 标签。否则,您可以创建一个 URL 映射,将请求直接映射到视图。
使用 Grails 1.2,您可以创建 命名 URL 映射 直接映射到视图:
然后将其与链接标记一起使用:
或
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.Othewise you can create a URL Mapping that maps a request directly to a view.
Using Grails 1.2 you can create a named URL Mapping that maps directly to a view:
and then use it with the link tag:
or
有一个 uri 属性 未记录,但您可以在 < a href="http://github.com/grails/grails/blob/master/grails/src/java/org/codehaus/groovy/grails/plugins/web/taglib/ApplicationTagLib.groovy" rel="noreferrer">来源:
HTH
There's a uri attribute that's undocumented , but you can see it in the source:
HTH
从 Grails 2.x 开始,这是不可能的。直接链接到 .gsp 的能力是一个安全缺陷,可用于避免
@Secured
注释。 URL 映射方法仍然有效,如 @Colin Harrington 的答案所示。请参阅:GRAILS-7542:可通过 URL 模式访问视图
As of Grails 2.x, this is not possible. The ability to link directly to a .gsp was a security flaw that could be used to avoid the
@Secured
annotation. The URL mapping method does still work though as seen in @Colin Harrington's answer.See: GRAILS-7542: Views are accessible via a URL pattern