gpt4 book ai didi

java - GRAILS:永久链接/slug 生成方法?

转载 作者:行者123 更新时间:2023-11-30 04:57:34 25 4
gpt4 key购买 nike

有人有在 Grails 1.3.7/2.0.0.RC1 中生成 slugs 和永久链接的快速方法吗?主要限制:此方法应该适用于非拉丁字符。

俄语/保加利亚西里尔字母、德语变音符号等...

有什么建议吗?

最佳答案

Grails 2.0.0.RC1

来自2.0.0.RC1 docs :

Link Generation API

A general purpose LinkGenerator class is now available that is usableanywhere within a Grails application and not just within the contextof a controller. For example if you need to generate links in aservice or an asynchronous background job outside the scope of arequest:

LinkGenerator grailsLinkGenerator

def generateLink() { grailsLinkGenerator.link(controller:"book", action:"list") }

虽然没有明确说明,但我假设对 grailsLinkGenerator 的引用是通过依赖注入(inject)获得的

Grails 1.3.7

您可以使用createLinkresource标签来生成链接。如果您要生成永久链接,我假设您会希望这些是绝对 URL。如果是这样,您在使用这些标记时需要使用 absolutebase 属性。

如果您使用 absolute 属性,请务必在 Config.groovy 中设置 grails.serverURL 的值

链接持久性

上面的文本描述了如何在 Grails 应用程序中生成指向资源的链接,但没有说明如何使这些链接永久存在。 AFAIK,只要您不更改 URL 映射方案(如 UrlMappings.groovy 中定义)中使用的任何内容,资源链接将始终保持不变

默认情况下,URL 映射方案使用

  • 资源 ID
  • Controller 名称
  • 操作名称

因此,如果您从不更改这些感兴趣的链接,那么您应该做得很好。

关于java - GRAILS:永久链接/slug 生成方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8038376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com