@ResponseBody
@RequestMapping("/export")
public byte[] exportPhone(HttpServletResponse response) throws UnsupportedEncodingException {
StringBuffer buff = new StringBuffer();
List<User> users = userService.findAll();
for (int i = 0; i < users.size(); i++) {
buff.append(users.get(i).toString());
buff.append("\r\n");
}
String fileName = "用户" + StringUtil.dateFormat("yyyy年MM月dd日HH时mm分ss秒", new Date()) + ".txt";
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
return buff.toString().getBytes();
}
springboot 导出文件
最新推荐文章于 2024-07-24 10:16:14 发布