数据搬家,后台复制表格数据到另一张表里

版权声明: https://blog.csdn.net/weixin_41716049/article/details/84336599

数据搬家:就是把一个表的数据移到另一张表中

案列:把ExtCproducts :合同表的附件表   的数据复制一份到 ExtEproduct :运单表中的附件表里   exportProduct :运单表

 //获取合同表的附件表  的数据
           Set<ExtCproduct> extCproducts = contractProduct2.getExtCproducts();
                //new 一个hash以便等会存储数据
                HashSet<ExtEproduct> extEproductss = new HashSet<ExtEproduct>();
                for (ExtCproduct extCproductss : extCproducts) {//遍历获取合同表的附件表
                    //创建运单表中的附件表
                    ExtEproduct eproduct = new ExtEproduct();
                    //如果两个表中的字段名相同的话我们可以使用BeanUtils(Spring的).copyProperties  直接复制过来
                    BeanUtils.copyProperties(extCproductss, eproduct);
                    eproduct.setId(null); //防止属性对拷后id也对拷
                    extEproductss.add(eproduct); 
                    
                    
                }
                exportProduct.setExtEproducts(extEproductss);//把获取的值通过运单表的set方法赋值给附件表

猜你喜欢

转载自blog.csdn.net/weixin_41716049/article/details/84336599