From ea43ca93ad7611496f597d022eb3e152674368b1 Mon Sep 17 00:00:00 2001 From: poppoppuppylove <431792974@qq.com> Date: Sat, 28 Sep 2024 00:31:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AD=A6=E7=94=9F=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E9=83=A8=E5=88=86=EF=BC=88=E8=A1=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/StudentExcelListener.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/example/attendance/listener/StudentExcelListener.java diff --git a/src/main/java/com/example/attendance/listener/StudentExcelListener.java b/src/main/java/com/example/attendance/listener/StudentExcelListener.java new file mode 100644 index 0000000..8ef8a97 --- /dev/null +++ b/src/main/java/com/example/attendance/listener/StudentExcelListener.java @@ -0,0 +1,29 @@ +package com.example.attendance.listener; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.example.attendance.dto.StudentExcelDTO; +import com.example.attendance.entity.Student; +import com.example.attendance.mapper.StudentMapper; + +public class StudentExcelListener extends AnalysisEventListener { + private final StudentMapper studentMapper; + + public StudentExcelListener(StudentMapper studentMapper) { + this.studentMapper = studentMapper; + } + + @Override + public void invoke(StudentExcelDTO data, AnalysisContext context) { + Student student = new Student(); + student.setName(data.getName()); + student.setId(Long.valueOf(data.getStudentId())); + student.setCurrentPoints(0); // 初始积分为0 + studentMapper.insertStudent(student); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + // 处理完成后的操作 + } +}