文章目录
- 效果
- 实现
-
- 1,添加依赖
- 2,实体类
-
- Member.java
- MemberVO.java
- 3,校验、监听器
-
- ValidationTool.java
- ExcelReadListener.java
- 4,请求接口
- 参考博文
效果
输入:导入测试.xlsx
postman调用实例:
postman输出结果:
日志输出:
实现
1,添加依赖
easyexcel要去掉poi-ooxml-schemas子依赖,避免依赖冲突
validation是springboot自带的校验库,简化了校验工作
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.5</version>
<exclusions>
<exclusion>
<artifactId>poi-ooxml-schemas</artifactId>
<groupId>org.apache.poi</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
2,实体类
Member.java
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Member implements Serializable {
@NotBlank(message = "用户名不能为空")</