1.conrtoller
public Result uploadImg(SysImageVO sysImageVO, MultipartFile imgFile) throws IOException {
Result result = new Result<>();
sysImageVO.setContent(imgFile.getBytes());
sysImageService.uploadImg(sysImageVO);
return result;
}
public Result downloadImg(SysImageVO sysImageVO, HttpServletResponse response) throws IOException {
Result result = new Result();
// 业务处理
SysImageVO image = sysImageService.downloadImg(sysImageVO);
// 将content转化
byte[] content = (byte[]) image.getContent();
// 设置文件名
response.addHeader(“Content-Disposition”, “attachment;fileName=” + URLEncoder.encode(image.getName(), “UTF-8”) + “;”);
// 设置文件大小
response.setContentLength(Integer.parseInt(image.getSize()));
// 将图片流通过response对象返回
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
bos.write(content);
bos.close();
return result;
}
2.entity
private Object content; //二进制流
3.mapper
<?xml version="1.0" encoding="UTF-8"?>//bytea
insert into sys_image(id, name, content)
values (#{id, jdbcType=INTEGER},#{name, jdbcType=VARCHAR}, #{content})
</inser
t>
select
id, name, content
from sys_image
where id = #{id}
4.service
service不多说,对象传递即可。
[
新人创作打卡挑战赛
发博客就能抽奖!定制产品红包拿不停!
](https://blogdev.blog.csdn.net/article/details/124124117?utm_campaign=marketingcard&utm_source=qq_20143059&utm_content=115542019)
最后
小编这些年深知大多数初中级工程师,想要提升自己,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Java全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你需要这些资料,⬅专栏获取
g-uXZHyKup-1719522557183)]
[外链图片转存中…(img-h2cYwkNk-1719522557184)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你需要这些资料,⬅专栏获取