easyExcel导出

导入依赖

com.alibaba
easyexcel
2.2.6


ehcache
org.ehcache



实体类记得加get,set方法
public class TradeExpenseError extends BusinessEntity {

private static final long serialVersionUID = 1L;

/**
 * ID
 */
@ExcelIgnore
@TableId(value = "EXPENSE_ID", type = IdType.UUID)
@JsonProperty("expenseId")
private String expenseId;

/**
 * 标段id
 */
@ExcelIgnore
@TableField("PACKAGE_ID")
@JsonProperty("packageId")
private String packageId;



/**
 * 错误类别
 */
@ExcelProperty("错误类别")
@TableField("ERROR_TYPE")
@JsonProperty("errorType")
private String errorType;

/**
 * 错误项
 */
@ExcelIgnore
@TableField("ERROR_NAME")
@JsonProperty("errorName")
private String errorName;

/**
 * 招标人价格
 */
@ExcelIgnore
@TableField("TENDER_PRICE")
@JsonProperty("tenderPrice")
private Double tenderPrice;

/**
 * 投标人价格
 */
@ExcelIgnore
@TableField("BIDDER_PRICE")
@JsonProperty("bidderPrice")
private Double bidderPrice;

/**
 * 错误一致的企业名称
 */
@ExcelProperty("错误一致的企业名称")
@TableField("SAME_BIDDER_NAMES")
@JsonProperty("sameBidderNames")
private String sameBidderNames;

/**
 * 推送时间
 */
@ExcelIgnore
@TableField("PUSH_TIME")
@JsonSerialize(using = MyLocalDateTimeSerializer.class)
@JsonDeserialize(using = MyLocalDateTimeDeserializer.class)
@JsonProperty("pushTime")
private LocalDateTime pushTime;

}

导出
前端
<el-button type=“primary” @click=“easy” size=“small”>导出

easy: function (){
var param = this.search;
var url = qmutil.appendUrl(“/trade/tradeExpenseError/easyTradeCheckExl?userType=trade”,param);
location.href = url;
}

后端:及得list<实体类>不是list

//导出
@GetMapping(“/easyTradeCheckExl”)
@ResponseBody
public void easyTradeCheckExl() throws Exception{

    // 获取数据源
    List<Map<String, Object>> dataList =baseService.easy();
    // 这里注意 使用swagger 会导致各种问题,easyexcel官方文档推荐直接用浏览器或者用postman测试
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    response.setCharacterEncoding("utf-8");
    // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系   fileName要导入文件名字
    String fileName = URLEncoder.encode("chen", "UTF-8").replaceAll("\\+", "%20");
    response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
    EasyExcel.write(response.getOutputStream(), TradeExpenseError.class).sheet("qq").doWrite(dataList);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值