首先效果图如下所示:数据从数据库查询出来之后导出成csv文件
csv文件其实就是将数据进行逗号分隔,但是csv文件还支持使用excel/wps 来打开,下面就是我使用excel打开后的数据格式:
其实总体实现还是比较简单的,就是将从数据库查询出来的数据写进csv的文件
其他就不多说了,下面直接上代码:
package com.example.txsmsboot.controller;
import com.example.txsmsboot.entity.Teacher;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.ByteArrayOutputStream;
impor