开发者

Grails resource paths in controller

开发者 https://www.devze.com 2023-02-04 19:43 出处:网络
Say I\'m passing a list of image urls from the server to the frontend. images/ image1.jpg image2.jpg image3.jpg

Say I'm passing a list of image urls from the server to the frontend.

images/
    image1.jpg
    image2.jpg
    image3.jpg

Now I'm just listing the file names, but I need to refe开发者_运维知识库rence the absolute path (/application/images/image1.jpg). Basically the equivalent of ${resource} server side.


You can call this code in your controller:

String pathToImage1 = g.resource(dir: 'images', file: 'image1.jpg', absolute: true)

Flag 'absolute' may be skipped.


for reading file (cvs, xml, img ,...) from controller I use:

def csv = grailsAttributes.getApplicationContext().getResource("/data/jak.csv").getFile()

Regards Tom


You can call tags from controllers - see http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.2.2.6%20Tags%20as%20Method%20Calls

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号