vue页面中要显示当前表没有的字段,并能够满足后台导出

因为只有一个字段,我就没做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更简单解决,害**

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值