欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

csv文件下载

程序员文章站 2022-04-04 12:13:04
...
BufferedOutputStream bos = null;
OutputStream fos = null;
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
//这个就就是弹出下载对话框的关键代码
response.setHeader("Content-disposition",
"attachment;filename=" +
URLEncoder.encode("投票讨论.csv", "utf-8"));
String headers = "编号,内容,状态,发布人,发布时间,审核人,审核时间,审核备注,来源\n";
bos.write(headers.getBytes("GBK"));
VoteDscs dsc = null;
String id,content,status,puber,pubTime,auditer,auditedTime,auditedRemark,source;
if(results!=null && results.size()>0){
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for(int i=0;i<results.size();i++){
dsc = results.get(i);
id=dsc.getRstId()+"";
content = dsc.getRstContent();
if(StringUtils.isEmpty(dsc.getIsAudited())){
status = "";
}else{
switch(Long.valueOf(dsc.getIsAudited()).intValue()){
case 0:
status = Constants.DISCUSS_CHECK_WAITING_CN;
break;
case 1:
status = Constants.DISCUSS_CHECK_SUCCESS_CN;
break;
default:
status="";
break;
}
}
puber = dsc.getPubPersonId()+"";
if(dsc.getPubTime()!=null){
pubTime = df.format(dsc.getPubTime());
}else{
pubTime = "";
}
auditer = dsc.getAuditor()+"";
if(dsc.getAuditDate()!=null){
auditedTime = df.format(dsc.getAuditDate());
}else{
auditedTime = "";
}
auditedRemark = dsc.getRemark();
if(dsc.getRstSource()==null){
source = "";
}else{
switch(Long.valueOf(dsc.getRstSource()).intValue()){
case 0:
source = Constants.SOURCE_MOBILE_CN;
break;
case 1:
source = Constants.SOURCE_TV_CN;
break;
case 2:
source= Constants.SOURCE_PC_CN;
break;
default:
source = "";
break;
}
}
bos.write((id+","+content+","+status+","+puber+","+pubTime+","+auditer+","+auditedTime+","+auditedRemark+","+source+"\n").getBytes("GBK"));
}
}
bos.flush();
fos.close();
bos.close();
return null;
相关标签: Mobile