生成职业代码工具类,可以参考当前文件目录下的aloc.xls文件,生成这样的数据结构微链可以使用mui框架的多级联动
工具类OccupationUtil.java
import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import com.alibaba.fastjson.JSON;public class OccupationUtil { public static void main(String[] args) throws IOException, Exception { //alOc(); alOc2(); } public static void alOc() throws Exception, IOException{ List<Element> rootElement=new ArrayList<Element>(); Set<String> rootSet=new LinkedHashSet<String>(); int start=1; POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("D:/aloc.xls")); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet=wb.getSheetAt(0); for(int i=1;i<741;i++){ HSSFRow hSSFRow=sheet.getRow(i); HSSFCell cell=hSSFRow.getCell(0); rootSet.add(cell.getStringCellValue()); } for(String str:rootSet){ Element element=new Element(); element.setValue((start++)+""); element.setText(str); List<Element> secondElement=new ArrayList<Element>(); element.setChildren(secondElement); Set<String> secondSet=new LinkedHashSet<String>(); for(int i=1;i<741;i++){ HSSFRow hSSFRow=sheet.getRow(i); HSSFCell cell0=hSSFRow.getCell(0); HSSFCell cell1=hSSFRow.getCell(1); if(str.equals(cell0.getStringCellValue())){ secondSet.add(cell1.getStringCellValue()); } } for(String str2:secondSet){ Element element2=new Element(); element2.setValue((start++)+""); element2.setText(str2); List<Element> thridElement=new ArrayList<Element>(); element2.setChildren(thridElement); Set<String> thridSet=new LinkedHashSet<String>(); for(int i=1;i<741;i++){ HSSFRow hSSFRow=sheet.getRow(i); HSSFCell cell0=hSSFRow.getCell(0); HSSFCell cell1=hSSFRow.getCell(1); HSSFCell cell2=hSSFRow.getCell(2); HSSFCell cell3=hSSFRow.getCell(3); if(str.equals(cell0.getStringCellValue())&&str2.equals(cell1.getStringCellValue())){ thridSet.add(cell1.getStringCellValue()); Element element3=new Element(); element3.setText(cell3.getStringCellValue()); element3.setValue(cell2.getStringCellValue()); thridElement.add(element3)