0
这是我在grails项目上的代码,我想创建csv文件并发送链接以便通过此链接下载?如何呈现可下载的文件wihich在localhost上:8080
当我想打开此链接不起作用。
我的项目是在localhost:8080/projectname/
运行我的链接将是这样的:localhost:8080/projectname/Abc/grails-app/QueryStringCSVFiles/test.csv
def db = new Sql(dataSource)
def result = db.rows("SELECT id,holderName,reportedCountry FROM Claims")
def out = new File('../Abc/grails-app/QueryStringCSVFiles/test.csv')
def out1 = new File('../Abc/grails-app/QueryStringCSVFiles/test1.csv')
def row1 = ["ID", "HolderName","ReportedCountry"]
out.append row1.join(',')
out.append '\n'
out1.append row1.join(',')
out1.append '\n'
result.each {
def row = [it.id, it.holderName,it.reportedCountry]
out.append row.join(',')
out.append '\n'
out1.append row.join(',')
out1.append '\n'
}
def link = [
link1: "http://localhost:8080/projectname/Abc/grails-app/QueryStringCSVFiles/test.csv",
link2: "http://localhost:8080/projectname/Abc/grails-app/QueryStringCSVFiles/test1.csv"
]
def links = [link:[link]]
render links as JSON
哪里'Java'?定义“不起作用”。 – 2014-10-28 08:12:54
您无法写入文件系统,希望grails将它们放在那里交付。 – cfrick 2014-10-28 09:00:27