diff --git a/src/com/fh/controller/sunvote/student/StudentController.java b/src/com/fh/controller/sunvote/student/StudentController.java index 8262ea7..43d6d1a 100644 --- a/src/com/fh/controller/sunvote/student/StudentController.java +++ b/src/com/fh/controller/sunvote/student/StudentController.java @@ -61,7 +61,7 @@ public class StudentController extends BaseController { if(!Jurisdiction.buttonJurisdiction(menuUrl, "add")){return null;} //校验权限 ModelAndView mv = this.getModelAndView(); PageData pd = new PageData(); - pd = this.getPageData(); + pd = this.getPageData(); studentService.save(pd); mv.addObject("msg","success"); mv.setViewName("save_result"); @@ -108,6 +108,8 @@ public class StudentController extends BaseController { public ModelAndView goUploadExcel()throws Exception{ ModelAndView mv = this.getModelAndView(); mv.addObject("pd", getPageData()); + + mv.setViewName("sunvote/student/uploadexcel"); return mv; } @@ -141,20 +143,23 @@ public class StudentController extends BaseController { if(temp.get("var" + j) == null){ break ; } - savePd.put(pd.getString("var" + j).toUpperCase(), temp.get("var" + j)); + if(temp.get("var" + j) != null && !"".equals(temp.get("var" + j).toString())){ + savePd.put(pd.getString("var" + j).toUpperCase(), temp.get("var" + j)); + } } if(!savePd.containsKey("ID")){ - String studentId = this.get32UUID(); - savePd.put("ID", studentId); - studentService.save(savePd); - - - if (classID != null && termID != null) { - savePd.put("STUDENT_ID", studentId); - savePd.put("CLASSROSTER_ID", get32UUID()); - savePd.put("TEAMID", termID); - savePd.put("SCLASS_ID", classID); - classrosterService.save(savePd); + if (savePd.values().size() > 0) { + String studentId = this.get32UUID(); + savePd.put("ID", studentId); + studentService.save(savePd); + + if (classID != null && termID != null) { + savePd.put("STUDENT_ID", studentId); + savePd.put("CLASSROSTER_ID", get32UUID()); + savePd.put("TEAMID", termID); + savePd.put("SCLASS_ID", classID); + classrosterService.save(savePd); + } } }else{ diff --git a/src/com/fh/util/ObjectExcelRead.java b/src/com/fh/util/ObjectExcelRead.java index 6521b2d..51dc8a2 100644 --- a/src/com/fh/util/ObjectExcelRead.java +++ b/src/com/fh/util/ObjectExcelRead.java @@ -10,65 +10,69 @@ import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; - +/** + * @version + */ public class ObjectExcelRead { /** - * @param filepath //文件路径 - * @param filename //文件名 - * @param startrow //开始行号 - * @param startcol //开始列号 - * @param sheetnum //sheet + * @param filepath + * //文件路径 + * @param filename + * //文件名 + * @param startrow + * //开始行号 + * @param startcol + * //开始列号 + * @param sheetnum + * //sheet * @return list */ - public static List readExcel(String filepath, String filename, int startrow, int startcol, int sheetnum) { + public static List readExcel(String filepath, String filename, + int startrow, int startcol, int sheetnum) { List varList = new ArrayList(); try { File target = new File(filepath, filename); FileInputStream fi = new FileInputStream(target); HSSFWorkbook wb = new HSSFWorkbook(fi); - HSSFSheet sheet = wb.getSheetAt(sheetnum); //sheet 从0开始 - int rowNum = sheet.getLastRowNum() + 1; //取得最后一行的行号 - - for (int i = startrow; i < rowNum; i++) { //行循环开始 - + HSSFSheet sheet = wb.getSheetAt(sheetnum); // sheet 从0开始 + int rowNum = sheet.getLastRowNum() + 1; // 取得最后一行的行号 + for (int i = startrow; i < rowNum; i++) { // 行循环开始 PageData varpd = new PageData(); - HSSFRow row = sheet.getRow(i); //行 - int cellNum = row.getLastCellNum(); //每行的最后一个单元格位置 - - for (int j = startcol; j < cellNum; j++) { //列循环开始 - + HSSFRow row = sheet.getRow(i); // 行 + int cellNum = row.getLastCellNum(); // 每行的最后一个单元格位置 + for (int j = startcol; j < cellNum; j++) { // 列循环开始 HSSFCell cell = row.getCell(Short.parseShort(j + "")); String cellValue = null; if (null != cell) { - switch (cell.getCellType()) { // 判断excel单元格内容的格式,并对其进行转换,以便插入数据库 - case 0: - cellValue = String.valueOf((int) cell.getNumericCellValue()); - break; - case 1: + int type = cell.getCellType(); + if (type == 0) { + cellValue = String.valueOf((long) cell + .getNumericCellValue()); + } + if (type == 1) { cellValue = cell.getStringCellValue(); - break; - case 2: + } + if (type == 2) { cellValue = cell.getNumericCellValue() + ""; - // cellValue = String.valueOf(cell.getDateCellValue()); - break; - case 3: + } + if (type == 3) { cellValue = ""; - break; - case 4: - cellValue = String.valueOf(cell.getBooleanCellValue()); - break; - case 5: - cellValue = String.valueOf(cell.getErrorCellValue()); - break; + } + if (type == 4) { + cellValue = String.valueOf(cell + .getBooleanCellValue()); + } + if (type == 5) { + cellValue = String + .valueOf(cell.getErrorCellValue()); } } else { cellValue = ""; } - - varpd.put("var"+j, cellValue); - + varpd.put("var" + j, cellValue); + System.out.println(cellValue); } varList.add(varpd); } @@ -76,7 +80,7 @@ public class ObjectExcelRead { } catch (Exception e) { System.out.println(e); } - + return varList; } }