大神们,帮帮忙!!一个Excel涉及到其他表字段导入到数据库代码怎么搞呀!(mybatis环境下)
这是张单表的导入,,,多表呢?怎么搞呀,主要是对象的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;
}