Appearance
PropsUtil
shell
Props props = PropsUtil.get("config/application.properties");
String host = props.getStr("spring.redis.host");
Integer port = props.getInt("spring.redis.port");
//环境西悉尼
String active = props.getStr("spring.profiles.active", "dev");HttpUtil
上传文件
shell
MultiResource resources = new MultiResource(new InputStreamResource(file.getInputStream(), file.getOriginalFilename()));
Map<String, Object> params = MapUtil.of("file", resources);
String body = HttpRequest.post("http://xxx/xxx")
.header("Token", "xxx")
.form(params).execute().body();下载文件
shell
HttpUtil.downloadFile()ExcelUtil
Excel文件读取
shell
ExcelReader reader = ExcelUtil.getReader(file.getInputStream(), 0);
List<List<Object>> read = reader.read();
List<Object> heads = read.get(0);//表头
List<List<Object>> dataList = read.stream().filter(objects -> objects.get(0) instanceof Long).toList();Excel表头下载
shell
ExcelWriter writer = ExcelUtil.getWriter();
//设置行高和列宽
writer.setColumnWidth(0, 20);
writer.setColumnWidth(1, 25);
writer.setColumnWidth(2, 30);
writer.setDefaultRowHeight(22);
//设置标题样式
CellStyle hcs = writer.getHeadCellStyle();
Font font = writer.createFont();
font.setFontName("微软雅黑");
font.setFontHeightInPoints((short) 12);
font.setBold(true);
hcs.setFont(font);
writer.writeHeadRow(List.of("姓名", "电话", "所属群组"));
//导出excel
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("群组导入模板", StandardCharsets.UTF_8) + ".xls");
ServletOutputStream out = response.getOutputStream();
writer.flush(out, true);
writer.close();
IoUtil.close(out);