public class BeanGenerator {
/**
* 实体名称
*/
private final static String BEAN_NAME = "${beanName}";
private final static String BEAN_SINCE = "${since}";
private final static String BEAN_VERSION = "${version}";
private final static String BEAN_AUTHOR = "${author}";
private final static String BEAN_NAME_ONE_LOWER_CASE = "${beanNameOneLowerCase}";
/**
* 实体注释
*/
private final static String BEAN_NOTE = "${beanNote}";
private final static String BEAN_NOTE_ONE_LOWER_CASE = "${beanNoteOneLowerCase}";
/**
* 属性循环开始
*/
private final static String PARAMETER_FOR_BEGIN = "${parameterBegin}";
/**
* 属性循环结束
*/
private final static String PARAMETER_FOR_END = "${parameterEnd}";
/**
* 属性名称
*/
private final static String PARAMETER_NAME = "${parameterName}";
private final static String PARAMETER_NAME_ONE_LOWER_CASE = "${parameterNameOneLowerCase}";
private final static String PARAMETER_NAME_ONE_UPPER_CASE = "${parameterNameOneUpperCase}";
private final static String PARAMETER_NAME_ALL_LOWER_CASE = "${parameterNameAllLowerCase}";
private final static String PARAMETER_NAME_ALL_UPPER_CASE = "${parameterNameAllUpperCase}";
/**
* 属性注释
*/
private final static String PARAMETER_NOTE = "${parameterNote}";
private final static String PARAMETER_NOTE_ONE_LOWER_CASE = "${parameterNoteOneLowerCase}";
private final static String PARAMETER_NOTE_ONE_UPPER_CASE = "${parameterNoteOneUpperCase}";
private final static String PARAMETER_NOTE_ALL_LOWER_CASE = "${parameterNoteAllLowerCase}";
private final static String PARAMETER_NOTE_ALL_UPPER_CASE = "${parameterNoteAllUpperCase}";
/**
* 属性类别
*/
private final static String PARAMETER_CLASS = "${parameterClass}";
private final static String PARAMETER_CLASS_ONE_LOWER_CASE = "${parameterClassOneLowerCase}";
private final static String PARAMETER_CLASS_ONE_UPPER_CASE = "${parameterClassOneUpperCase}";
private final static String PARAMETER_CLASS_ALL_LOWER_CASE = "${parameterClassAllLowerCase}";
private final static String PARAMETER_CLASS_ALL_UPPER_CASE = "${parameterClassAllUpperCase}";
private final static String BEAN_ALL_PARAMETERS_SET = "${allParametersSet}";
private final static String BEAN_ALL_PARAMETERS = "${allParameters}";
private final static String BEAN_ALL_PARAMETERS_STR = "${allParametersStr}";
private final static String BEAN_ALL_PARAMETERS_COMMENT = "${allParametersComment}";
private String importBeanExcelPath = "";
private String outputBasePath = "";
private String[] templatePaths = {
};
private List<Bean> beans;
private HSSFWorkbook hssfWorkbook;
private HSSFSheet hssfSheet;
private HSSFRow hssfRow;
private HSSFCell hssfCell;
private BufferedReader bufferedReader;
public BeanGenerator(String[] templatePaths, String importBeanExcelPath,
String outputBasePath) throws IOException {
this.templatePaths = templatePaths;
this.importBeanExcelPath = importBeanExcelPath;
this.outputBasePath = outputBasePath;
init();
}
public void init() throws IOException {
File file = new File(importBeanExcelPath);
FileInputStream fileInputStream = new FileInputStream(file);
hssfWorkbook = new HSSFWorkbook(fileInputStream);
if(hssfWorkbook.getNumberOfSheets()>1){
beans = new ArrayList<Bean>(hssfWorkbook.getNumberOfSheets()-1);
}else{
throw new IOException("workbook has no table sheets.");
}
}
/**
* 根据行列,返回EXCEL中cell的字符串
* @param row
* @param col
* @return
*/
private String cellValue(int row, int col) {
String value = null;
hssfRow = hssfSheet.getRow(row);
if (Util.isNull(hssfRow))
return null;
hssfCell = hssfRow.getCell((short) col);
if (Util.isNull(hssfCell))
return null;
value = hssfCell.getStringCellValue();
return value.trim();
}