Java导出功能 后台代码

1.设置表头数据
package com.****.vo; 实体类
import cn.afterturn.easypoi.excel.annotation.Excel;
public class ExportExcel extends BaseInfo
{

@Excel(name = "数据ID", orderNum = "0")
private String buyId;

@Excel(name = "公众号ID", orderNum = "1")
private String weixinId;

@Excel(name = "项目ID", orderNum = "2")
private String projId;

@Excel(name = "登陆者部门", orderNum = "3")
private String departId;

@Excel(name = "公众号名称", orderNum = "4")
private String wxName;

@Excel(name = "阅读量", orderNum = "5")
private int reading;

@Excel(name = "点赞量", orderNum = "6")
private int thumbs;

@Excel(name = "微信联系人数", orderNum = "7")
private int weixin;

@Excel(name = "电话联系人数", orderNum = "8")
private int mobile;

@Excel(name = "报名人数", orderNum = "9")
private int enroll;

@Excel(name = "门票购买数", orderNum = "10")
private int ticket;

@Excel(name = "门票实收金额", orderNum = "11")
private int dmoney;

@Excel(name = "投放位置", orderNum = "12")
private String seat;

@Excel(name = "投放金额", orderNum = "13")
private int bmoney;

@Excel(name = "部门", orderNum = "14")
private String departName;

@Excel(name = "项目名称", orderNum = "15")
private String projName;

@Excel(name = "投放人", orderNum = "16")
private String realName;

@Excel(name = "登陆者级别", orderNum = "17")
private int level;

@Excel(name = "用户ID", orderNum = "18")
private String userId;

@Excel(name = "备注", orderNum = "19")
private String remark;

@Excel(name = "是否有签单", replace = {"否_0", "是_1"}, orderNum = "20")
private int isSign;

@Excel(name = "投放日期", exportFormat = "yyyy-MM-dd", orderNum = "21")
private String buyDate;

@Excel(name = "创建日期", exportFormat = "yyyy-MM-dd", orderNum = "22")
private String regTime;

public ExportExcel(){
    
}

public ExportExcel(String buyId, String weixinId,String userId,int level,String departId, String wxName, int reading, int thumbs,
                   int weixin, int mobile, int enroll, int ticket, int dmoney, int bmoney,String departName, String seat, String projName, String realName, String remark, int isSign,
                   String buyDate,String regTime)
{
    this.buyId = buyId;
    this.weixinId = weixinId;
    this.userId = userId;
    this.level =level;
    this.departId = departId;
    this.wxName = wxName;
    this.reading = reading;
    this.thumbs = thumbs;
    this.weixin = weixin;
    this.mobile = mobile;
    this.enroll = enroll;
    this.ticket = ticket;
    this.dmoney = dmoney;
    this.bmoney = bmoney;
    this.seat = seat;
    this.projName = projName;
    this.departName = departName;
    this.realName = realName;
    this.remark = remark;
    this.buyDate = buyDate;
    this.isSign = isSign;
    this.regTime = regTime;
}

public String getBuyId()
{
    return buyId;
}

public void setBuyId(String buyId)
{
    this.buyId = buyId;
}

public String getWeixinId()
{
    return weixinId;
}

public void setWeixinId(String weixinId)
{
    this.weixinId = weixinId;
}

public String getWxName()
{
    return wxName;
}

public void setWxName(String wxName)
{
    this.wxName = wxName;
}

public int getReading()
{
    return reading;
}

public void setReading(int reading)
{
    this.reading = reading;
}

public int getThumbs()
{
    return thumbs;
}

public void setThumbs(int thumbs)
{
    this.thumbs = thumbs;
}

public int getWeixin()
{
    return weixin;
}

public void setWeixin(int weixin)
{
    this.weixin = weixin;
}

public int getMobile()
{
    return mobile;
}

public void setMobile(int mobile)
{
    this.mobile = mobile;
}

public int getEnroll()
{
    return enroll;
}

public void setEnroll(int enroll)
{
    this.enroll = enroll;
}

public int getTicket()
{
    return ticket;
}

public void setTicket(int ticket)
{
    this.ticket = ticket;
}

public int getDmoney()
{
    return dmoney;
}

public void setDmoney(int dmoney)
{
    this.dmoney = dmoney;
}

public String getSeat()
{
    return seat;
}

public void setSeat(String seat)
{
    this.seat = seat;
}

public int getBmoney()
{
    return bmoney;
}

public void setBmoney(int bmoney)
{
    this.bmoney = bmoney;
}

public String getDepartName()
{
    return departName;
}

public void setDepartName(String departName)
{
    this.departName = departName;
}

public String getProjName()
{
    return projName;
}

public void setProjName(String projName)
{
    this.projName = projName;
}

public String getRealName()
{
    return realName;
}

public void setRealName(String realName)
{
    this.realName = realName;
}

public String getRemark()
{
    return remark;
}

public void setRemark(String remark)
{
    this.remark = remark;
}

public int getIsSign()
{
    return isSign;
}

public void setIsSign(int isSign)
{
    this.isSign = isSign;
}

public String getBuyDate()
{
    return buyDate;
}

public void setBuyDate(String buyDate)
{
    this.buyDate = buyDate;
}

public String getRegTime()
{
    return regTime;
}

public void setRegTime(String regTime)
{
    this.regTime = regTime;
}

public String getUserId()
{
    return userId;
}

public void setUserId(String userId)
{
    this.userId = userId;
}

public int getLevel()
{
    return level;
}

public void setLevel(int level)
{
    this.level = level;
}

public String getDepartId()
{
    return departId;
}

public void setDepartId(String departId)
{
    this.departId = departId;
}

public String getProjId()
{
    return projId;
}

public void setProjId(String projId)
{
    this.projId = projId;
}

}

2.dao 层
List<***> exportDate(*** aaa) throws Exception;

3.service 层
//数据导出
List exportDate( *** aaa) throws Exception;
impl正常操作

4.控制层
@RequestMapping(value = “/export”,produces = “application/json”)
public void export(HttpServletResponse response,HttpServletRequest request, BuyInfo buy) throws Exception{
//模拟从数据库获取需要导出的数据(DateUtils.addDays(new Date(),3), DateUtils.addDays(new Date(),3)
JSONObject js = (JSONObject)request.getSession().getAttribute(KeyWord.USERSESSION);
JSONObject obj = new JSONObject();

    if(js == null || "".equals(js)){

//将实体对象转换为JSON Object转换
// JSONObject responseJSONObject = //JSONObject.fromObject(responseObject);
// response.setCharacterEncoding(“UTF-8”);
// response.setContentType(“application/json; charset=utf-8”);
// PrintWriter out = null;
// try {
// out = response.getWriter();
// out.append(responseJSONObject.toString());
// logger.debug(“返回是\n”);
// logger.debug(responseJSONObject.toString());
// } catch (IOException e) {
e.printStackTrace();
// } finally {
// if (out != null) {
// out.close();
// }
// }

       // obj.put("status", 0);
       // obj.put("showMessage", "请先登录!");
       log.info("用户没有登录 ! 请先登录 ! ");
    }else{
        Integer level = js.getInteger("level");
        String userId = js.getString("userId");
        String departId = js.getString("departId");
        buy.setLevel(level);
        buy.setUserId(userId);
        buy.setDepartId(departId);
        List<ExportExcel> buyList = buyService.exportDate( buy);
        //导出操作 

// FileOutputStream stream = new FileOutputStream();
EasyPOIModel.exportExcel(buyList,“投放数据”, “数据”,ExportExcel.class,“投放数据导出.xls”,response);
}

  }

5.需要参数(startTime endTime )
前端传参方试window.open(API.host+API.dataOutCatch+"?startTime="+this.datePick[0]+"&endTime="+this.datePick[1])

不需要请求头

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值