如何在action中给外键赋值
本帖最后由 Mr_fault 于 2014-03-28 11:50:11 编辑
package com.ZQULife.action;
import java.io.File;
import java.io.FileInputStream;
import
java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.ZQULife.service.CoursesManager;
import com.ZQULife.domain.*;
import com.opensymphony.xwork2.ActionSupport;
public class ImportExcelAction extends ActionSupport
{
private StudentDAO dao = new StudentDAO();
private File excelFile;
private String excelFileFileName;
private ExcelWorkSheet<Courses> excelWorkSheet;
public File getExcelFile()
{
return excelFile;
}
public void setExcelFile(File excelFile)
{
this.excelFile = excelFile;
}
public String getExcelFileFileName()
{
return excelFileFileName;
}
public void setExcelFileFileName(String excelFileFileName)
{
this.excelFileFileName = excelFileFileName;
}
public ExcelWorkSheet<Courses> getExcelWorkSheet()
{
return excelWorkSheet;
}
public void setExcelWorkSheet(ExcelWorkSheet<Courses> excelWorkSheet)
{
this.excelWorkSheet = excelWorkSheet;
}
private Workbook createWorkBook(InputStream is) throws
IOException
{
if (excelFileFileName.toLowerCase().endsWith("xls"))
{
return new HSSFWorkbook(is);
}
if (excelFileFileName.toLowerCase().endsWith("xlsx"))
{
return new XSSFWorkbook(is);
}
return null;
}
public String importExcel() throws Exception
{
Workbook workbook = createWorkBook(new FileInputStream(excelFile));
Sheet sheet = workbook.getSheetAt(0);
excelWorkSheet = new ExcelWorkSheet<Courses>();
excelWorkSheet.setSheetName(sheet.getSheetName());
Row firstRow = sheet.getRow(0);
Iterator<Cell> iterator = firstRow.iterator();
List<String> cellNames = new ArrayList<String>();
while (iterator.hasNext())
{
cellNames.add(iterator.next().getStringCellValue());
}
for (int i = 1; i <= sheet.getLastRowNum(); i++)
{
Row row = sheet.getRow(i);
Courses courses= new Courses();
// Alltime alltime= new Alltime();
// student.setId((int) row.getCell(0).getNumericCellValue());
/* student.setName(row.getCell(0).getStringCellValue());
student.setSex(row.getCell(1).getStringCellValue());
student.setBirthday(row.getCell(2).getDateCellValue());
*/
/