grails 中静态资源的通用 url 映射
我已经在 grails 中配置了一些静态资源,如下所示
"/book/$id?"(resource:"book")
"/author/$id?"(resource:"author")
,但我想要这个更通用的资源,但
"/$controller/$id?"(resource: controller)
不起作用...(获取 404)
如何为 grails 中的静态资源配置通用 url 映射?
I have configured some restful resources in grails like this
"/book/$id?"(resource:"book")
"/author/$id?"(resource:"author")
But I want to to this more generic like
"/$controller/$id?"(resource: controller)
which doesn't work... (getting 404)
How can i configure a generic url mapping for restful resources in grails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来映射的“资源”部分是在启动时评估的,而不是在执行实际请求时评估的(通过对此进行猜测)。因此,我认为您需要根据应用程序启动时可用的域类动态“预加载”您想要的 UrlMappings 集。像这样的事情可能会起作用:
It would seem that the "resource" portion of the mapping is evaluated on startup, not on execution of the actual request (a guess from playing around with this). Therefore, I think you need to "preload" the set of UrlMappings you want dynamically based on the Domain classes available on application startup. Something like this might do the trick:
满足您需求的正确映射完全取决于您想要实现的目标(无法从问题中确定)。
考虑一个通用映射:
这会将 URL 的第一部分映射到同名的控制器,第二部分映射到该控制器的操作,第三部分映射到域类实例的唯一标识符。
使用此映射的示例:
The correct mapping for your needs depends entirely on what you are trying to achieve (which can't be determined from the question).
Consider a generic mapping:
This will map the first part of the URL to a controller of the same name, the second part to an action of that controller and the third part to what should be a unique identifier for a domain class instance.
Examples that work with this mapping: