本文不建议阅读。作者已有更好的解决方案:戳这里
前言
最近做公司项目,用到了POI实现Excel导入导出的功能。
整个功能做下来,发现很多大牛的文章都已经过时,会报类似The method setBorderBottom(short) from the type HSSFCellStyle is deprecated的警告,直接使用@SupressWarnings忽略警告显然是不负责任的。因此我直接去翻了Apache POI的官方文档,使用了目前官方推荐的新实现方法。
顺便发出来,方便没有翻阅英文官方文档习惯的大家。
过两天发实现导入Excel的示例文章。
项目结构简介
Student.java:学生实体。
StudentService.java:业务类。
StudentController.java: web层。
(具体每一步的介绍在代码中都有详细的解释,此处不再赘述。如果疑惑的地方欢迎留言讨论。)
Excel导出代码展示
Student.java
@Entity
@NoArgsConstructor
@Getter
@Setter
public class Student implements Serializable{
/**
* @fields serialVersionUID
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "idGenerator")