# import-excel **Repository Path**: zclget/import-excel ## Basic Information - **Project Name**: import-excel - **Description**: 1、easyExcel解析excel文件 2、解析完展示功能 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-07-03 - **Last Updated**: 2022-05-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: easyExcel ## README # 解析excel ## 1、添加easyExcel依赖 ```xml com.alibaba easyexcel 2.2.6 ``` ## 2、添加监听器 ```java public class StudentListener extends AnalysisEventListener { @Getter private List studentList = new ArrayList(); public StudentListener() { super(); studentList.clear(); } /** * 每一条数据解析都会调用 */ @Override public void invoke(Student student, AnalysisContext context) { studentList.add(student); } /** * 所有数据解析完成都会调用 */ @Override public void doAfterAllAnalysed(AnalysisContext context) { studentList.forEach(System.out::println); } } ``` ## 3、添加excel表头封装对象 ```java @Data @NoArgsConstructor @AllArgsConstructor @HeadRowHeight(20) @ColumnWidth(20) @ContentRowHeight(15) public class Student { @ExcelProperty(index = 0, value = "学号") private String sno; @ExcelProperty(index = 1, value = "姓名") private String name; @ExcelProperty(index = 2, value = "年龄") private Integer age; @ExcelProperty(index = 3, value = "性别") private String gender; @ExcelProperty(index = 4, value = "籍贯") private String nativePlace; @ExcelProperty(index = 5, value = "入学时间") private Date enrollmentTime; } ``` ## 4、接口调用 ```java @RequestMapping(value = "import") public List importStudentInfos(MultipartFile file) throws IOException { StudentListener studentListener = new StudentListener(); // 读取excel解析成封装对象 EasyExcel.read(file.getInputStream(), Student.class, studentListener).sheet().doRead(); // 返回解析的结果 return studentListener.getStudentList(); } ``` # springboot整合thymeleaf及访问静态路径 ## 1、添加依赖 ```xml org.springframework.boot spring-boot-starter-thymeleaf ``` ## 2、在resources目录下创建静态资源文件 - 创建templates放入html文件 - 创建static目录 - 创建js和css目录 ## 3、配置静态资源访问(默认自带,可不配) ```yaml spring: resources: static-locations: classpath:/templates/,classpath:/static/ ``` ## 4、html中引入静态资源(href可替换th:href="@{/css/bootstrap.min.css}") ```html ```