UrlMapping和文件扩展名 [英] UrlMapping and file name extension

查看:125
本文介绍了UrlMapping和文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下url-mapping:

 名字a:/ a / $ file{
controller ='attachment'
action ='get'
}

和I想要像这样使用

 < g:link mapping =aparams =[file:name]> ; $ {名称}< /克:链接> 

其中 name 可以是:myfile.pdf



问题是,当我到达我的控制器时,Grails删除扩展名,所以我得到

  params.file =myfile

我想要什么能够在我的域对象中搜索完整的文件名。



我试图设置

  grails.mime.file.extensions = false 

但后来我所有使用withFormat的控制器都无法正常工作。有没有办法,我可以找到扩展的价值?

  grails.mime.file.extensions = true 

并使用下一个映射

 / excursion / $ path **{
controller =excursion
action =sweet
}

在控制器


$ b $

  def path = params.path 
if(!FilenameUtils.getExtension(path)&& request.format){
path + =。$ {request.format}
}


I have the following url-mapping:

name a: "/a/$file" {
    controller = 'attachment'
    action = 'get'
}

and I want to use it like this

<g:link mapping="a" params="[file: name]">${name}</g:link>

Where name could be: "myfile.pdf"

Problem is, when I get to my controller, Grails strips the extension, so I get

 params.file = "myfile"

Where I would like "myfile.pdf" to be able to search for the full file name in my domain objects.

I have tried to set

 grails.mime.file.extensions = false

But then all my controllers using "withFormat" is not working. Is there a way, where I can find the value of the extension?

解决方案

i have

 grails.mime.file.extensions = true

and using next mapping

"/excursion/$path**" {
  controller = "excursion"
  action = "sweet"
}

In Controller

def path = params.path
    if (!FilenameUtils.getExtension(path) && request.format) {
      path += ".${request.format}"
    }

这篇关于UrlMapping和文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆