Grails 不会使用标签在子文件夹中显示图像

str*_*sam 3 grails resources

我在 Grails 项目中有图像文件,例如:

grails-app/assets/images/admin/img1.jpg
Run Code Online (Sandbox Code Playgroud)

我试图将其显示为:

<g:img dir="images/admin" file="img1.jpg">
Run Code Online (Sandbox Code Playgroud)

在开发环境(Grails 2.4)中,它没有出现。我得到 404。但是,如果我将图像复制到:

grails-app/assets/images/img1.jpg
Run Code Online (Sandbox Code Playgroud)

并更改如下代码:

<g:img dir="images" file="img1.jpg">
Run Code Online (Sandbox Code Playgroud)

有用。

我正在使用的插件:

build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:1.9.9"

// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
Run Code Online (Sandbox Code Playgroud)

Vin*_*yon 5

从我所看到的 Abs 非常接近尝试。

 <asset:image src="admin/img1.jpg" />
Run Code Online (Sandbox Code Playgroud)

如果您参考:

http://bertramdev.github.io/asset-pipeline/guide/usage.html

在 4.3 下:

如果需要,也可以在子目录中引用资产,只需使用相对路径即可。

<asset:image src="icons/delete.png"/>
Run Code Online (Sandbox Code Playgroud)

所以他们已经在图像中并且有一个名为图标的文件夹

您还应该能够使用替代方法执行类似的操作:

<img src="${assetPath(src: 'admin/img1.jpg')}"/>
<g:img src="${assetPath(src: 'admin/img1.jpg')}"/>
Run Code Online (Sandbox Code Playgroud)