因为只有一个字段,我就没做VO类,在当前实体中添加了一个对象
## 实体类
// instore_doc的客户,只用于传值 + 导出所用字段
@Excel(name = "客户")
private String instoreCheckConsumer;
// instore_doc的对象,用来存储想要的客户信息
private InstoreDoc instoreDoc;
## xml
// sql的话正常写关联查询
<resultMap type="GoodsInfoHistory" id="GoodsInfoHistoryResult">
<result property="id" column="id"/>
.....
<association property="instoreDoc" resultMap="instoreDocMap"></association>
</resultMap>
<resultMap id="instoreDocMap" type="InstoreDoc">
<result property="checkConsumer" column="check_consumer"/>
</resultMap>
**查询页面展示就正常去做,下面是后台导出时的代码,因为实体字段中没有值,
导出结果也是空,选择用流的方式赋值,又因为赋值时避免对象为空报空指针异常,
选择三目运算,如果对象为空,重新实例化**
@PostMapping("/export")
public void export(HttpServletResponse response, GoodsInfoHistory goodsInfoHistory) throws IOException {
List<GoodsInfoHistory> list = goodsInfoHistoryService.selectGoodsInfoHistoryList(goodsInfoHistory);
// 给临时字段赋值,导出客户,对象不能为空,做三目运算
List<GoodsInfoHistory> newList = list.stream().peek(goodsInfo -> {
goodsInfo.setInstoreCheckConsumer(goodsInfo.getInstoreDoc()!=null?goodsInfo.getInstoreDoc().getCheckConsumer():new InstoreDoc().getCheckConsumer());
}).collect(Collectors.toList());
ExcelUtil<GoodsInfoHistory> util = new ExcelUtil<GoodsInfoHistory>(GoodsInfoHistory.class);
util.exportExcel(response, newList, "goods_info_history");
}
**因为之前不知道还要导出,想着就一个字段没必要用VO,后来知道后也懒得改了,实际上新建VO更简单解决,害**
vue页面中要显示当前表没有的字段,并能够满足后台导出
最新推荐文章于 2022-12-05 14:36:41 发布