Java之EasyExcel入门Demo

本文档介绍了如何快速上手使用Java的EasyExcel库,包括添加依赖、编写Dto、创建工具类、实现监听器和自定义转换器,特别关注了 LocalDate 的导入导出转换。此外,还提供了SPI测试的相关内容。
摘要由CSDN通过智能技术生成

Check it out on github

demo-easy-excel

DESC:

  • spring integration easy excel

快速上手:

pom.xml
<dependencies>
    <!-- spring 等公用部分由 父工程提供, 这里仅展示核心 -->
    <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>easyexcel</artifactId>
        <version>2.1.4</version>
    </dependency>
</dependencies>
编写Dto
@Data
public class DemoParentDto {
   

    @ExcelProperty(index = 0,value = {
   "序号"})
    private Integer num;

}
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public class DemoUserDto extends DemoParentDto{
   

    @ExcelProperty(value = {
   "姓名"})
    private String name;

    @ExcelProperty(value = {
   "性别"})
    private String sex;

    /**
     * @see LocalDateStringConverter
     */
    @ExcelProperty(value = "生日",converter = LocalDateStringConverter.class)
    @DateTimeFormat("yyyy-MM-dd")
    private LocalDate birthday;

    @ExcelProperty(value = {
   "年龄"})
    private Integer age;


    /**
     * 获取6个测试数据
     * @return 6个
     */
    public static List<DemoUserDto> getUserDtoTest6(Object search){
   
        List<DemoUserDto> list = new ArrayList<>();
        list.add(new DemoUserDto("quaint","男",LocalDate.of(2011,11,11),9));
        list.add(new DemoUserDto("quaint2","女",LocalDate.of(2001,11,1),19));
        list.add(new DemoUserDto("quaint3","男",LocalDate.of(2010,2,7),10));
        list.add
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值