zoukankan      html  css  js  c++  java
  • 导出CSV格式

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.util.CollectionUtils;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;

    import javax.servlet.http.HttpServletResponse;
    import javax.validation.Valid;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.io.UnsupportedEncodingException;
    import java.util.List;
    ....
    ...

    ...

    List<MatchRecordBo> matchRecordBos = matchRecordService.findMatchRecordList(matchRecordQueryBean);
    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append("匹配用户(微信),信物商品,信物编号,投放信物用户,匹配时间,匹配指数,匹配结果,答题结果").append(" ");
    for (MatchRecordBo item : matchRecordBos) {
    stringBuffer.append(item.getUserName()).append(",");
    stringBuffer.append(item.getProductName()).append(",");
    stringBuffer.append(item.getProductSn()).append(",");
    stringBuffer.append(item.getLeaveUserName()).append(",");
    stringBuffer.append(item.getCreateAt()).append(",");
    stringBuffer.append(item.getMatchScore()).append(",");
    stringBuffer.append(item.getStatus() == 1 ? "失败" : "成功" ).append(",");
    stringBuffer.append(item.getStatus() == 4 ? "成功" : "失败" ).append(" ");
    }

    byte[] byt = new byte[0];
    try {
    byt = stringBuffer.toString().getBytes("gb2312");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }

    // 设置响应
    response.setContentType("application/octet-stream");
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "max-age=30");
    response.setHeader("Content-Disposition",
    "attachment;filename="" + new String("匹配记录列表.csv".getBytes("UTF-8"), "iso8859-1"));
    try {
    OutputStream out = response.getOutputStream();
    // 写入输出结果
    out.write(byt);
    out.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    return stringBuffer.toString();
    ...
  • 相关阅读:
    MySql msi安装
    C# TextBox文本内容选中
    SQL 删除时间最靠前的几条数据
    Layui表格工具栏绑定事件失效问题
    Layui我提交表单时,table.reload(),表格会请求2次,是为什么?按下面的做
    table 中数据行循环滚动
    html 3D反转效果
    网页电子表数字样式
    power tool 强制撤销
    GHOST -ntexact 正常还原
  • 原文地址:https://www.cnblogs.com/yzf666/p/9669400.html
Copyright © 2011-2022 走看看