springboot下载 word文档后打开乱码
所属分类 springboot
浏览量 13
word文档放在 src/main/resources/template
下载接口 使用 ClassPathResource 读取
InputStream fileStream = null;
try {
ClassPathResource classPathResource = new ClassPathResource(filePath);
// 资源路径
// file:/xxx/target/classes/template/abc.docx
String url = classPathResource.getURL().toString();
fileStream = classPathResource.getInputStream();
byte[] bytes = IoUtil.readBytes(fileStream);
return bytes;
}finally{
IoUtil.close(fileStream);
}
src 和 target里的 文件大小不一样
/src/main/resources/template/abc.docx
/target/classes/template/abc.docx
word文档里 有占位符 {{reportCode}}
编译时会做占位符替换 ,导致乱码
org.apache.maven.plugins
maven-resources-plugin
3.1.0
UTF-8
xlsx
xls
lib
otf
ttf
加上 docx 配置后 ok
docx
上一篇
下一篇
大模型发展的 五元飞轮 和 Scaling Law
《睡后收入的真相:怎样让你躺着就能赚钱》精华笔记
个人公众号 ETF猎手
《AI时代生存手册:零基础掌握豆包》笔记
小龙虾 OpenClaw 核心原理