• 导出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();
    ...
  • 相关阅读:
    最长上升序列,首尾连接
    带权并查集&&并查集
    开发者的小天地-1
    Binary Tree Maximum Path Sum
    Linked List Cycle II
    动归熟手题单
    java 正则表达式-忽略大小写与多行匹配
    KO之tab栏切换
    Vue中通过属性绑定为元素绑定style
    Vue中通过属性绑定为元素设置class
  • 原文地址:https://www.cnblogs.com/yzf666/p/9669400.html
Copyright © 2020-2023  润新知