> java 读取json文件转换成list
File file = new File("F:\\test01.json");
JSONArray jsonArray = JSONUtil.readJSONArray(file, StandardCharsets.UTF_8);
List<Match01Vo> qxppNoMatch01List = JSONObject.parseArray(jsonArray.toString(), match01Vo.class);
> 用指定字符串,指定长度填充字符串(左边填充)
/**
* 用指定字符,指定长度,为指定的字符串填充字符串(左边)
*
* @param str String 原始字符
* @param c char 填充的字符
* @param len int 字符串长度
* @return
*/
public static String fillStringLeft(String str, String c, int len) {
if (str == null) {
str = "";
}
int strLen = str.getBytes().length;
len = len - strLen;
if (len <= 0) {
return str;
}
while (len > 0) {
str = c + str;
len--;
}
return str;
}
> 下载静态文件
@Operation(summary = "下载模版")
@PostMapping(value = "downloadTemplate")
public void downloadTemplate(HttpServletResponse response) {
InputStream is = null;
OutputStream os = null;
try {
String fileName = "质量报告导入.xlsx";
fileName = URLEncoder.encode(fileName, "utf-8");
ClassPathResource classPathResource = new ClassPathResource("templates/stockNew/质量报告导入.xlsx");
is = classPathResource.getInputStream();
response.setContentType("multipart/form-data");
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
os = response.getOutputStream();
IoUtil.copy(is, os);
} catch (IOException ex) {
ex.printStackTrace();
}finally {
IoUtil.close(is);
IoUtil.close(os);
}
}