CSV简介
逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文
本形式存储表格数据(数字和文本)。
示例代码
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.springbooks.bootTest.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UserController {
//BufferedOutputStream
@GetMapping("/csv")
public void csv(HttpServletResponse resp) throws IOException {
resp.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
resp.setHeader("Content-Disposition", "attachment;filename=111.csv");
resp.setCharacterEncoding("UTF-8");
ServletOutputStream os = resp.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
String[] titles = new String[]{"id","name","age"};
List