如果您在Grails的2.X的時候,你可以在Config.groovy中
配置目標目錄例如
grails.datapath.userguides =「C:/用戶/用戶1/userGuides/「
如果你想
配置這個取決於你可以做這樣的環境:
development {
grails.datapath.userguides = "C:/Users/user1/userGuides/"
}
test {
grails.datapath.userguides = "C:/anotherDirectory/userGuides/"
}
production {
grails.datapath.userguides = "/var/www/${appName}/userGuides/"
}
然後定義一個控制器來訪問您的文件,例如文檔這個動作sController
def downloadUserGuide()
{
... // code to get your entity file that you use in your example to do
... // file.getValue()
String path = grailsApplication.config.grails.datapath.userguides
String label = ... // If you want to display another file name
render(contentType: "application/pdf", file: new File(path + file.getValue()), fileName: label)
}
看看這個問題http://stackoverflow.com/questions/39536317/open-pdf-file-in-new-window-from-variable-path-name-in-gsp-頁面/ 39542861#39542861 –