大神们,帮帮忙!!一个Excel涉及到其他表字段导入到数据库代码怎么搞呀!(mybatis环境下)

qq_38754891 2018-03-16 10:18:08
这是张单表的导入,,,多表呢?怎么搞呀,主要是对象的set方法怎么获取(下面紫色部分)。。。。
private List<Salon> readExcelValue(Workbook wb) throws Exception {
// 得到第一个shell
Sheet sheet = wb.getSheetAt(0);

// 得到Excel的行数
this.totalRows = sheet.getPhysicalNumberOfRows();

// 得到Excel的列数(前提是有行数)
if (totalRows >= 1 && sheet.getRow(0) != null) {
this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
}

List<Salon> salonList = new ArrayList<Salon>();
Salon salon;
// 循环Excel行数,从第二行开始。标题不入库
for (int r = 1; r < totalRows; r++) {
Row row = sheet.getRow(r);
if (row == null)
continue;

salon = new Salon();
// 循环Excel的列
for (int i = 0; i < this.totalCells; i++) {
// 总店代码
if (i == 0) {
row.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
salon.setParentSalonCode(row.getCell(i).getStringCellValue());
} else if (i == 1) {//发廊代码
row.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
salon.setSalonCode(row.getCell(i).getStringCellValue());
} else if (i == 2) {//门店名称
row.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
salon.setName(row.getCell(i).getStringCellValue());
} else if (i == 3) {//代理商编码
row.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
salon.setAgentCode(row.getCell(i).getStringCellValue());
}
}
// 添加其他值,入库时需要

salonList.add(salon);
}
return salonList;
}
...全文
264 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

50,541

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧