后台访问windows下的图片
/** * @author A */ @CrossOrigin @RestController @Slf4j @Api(tags = "") public class ImageController { @Value("${picture.basePath}") private String PIC_BASE_PATH; /** * @return * @throws BaseException */ @RequestMapping(value="/image/ProductClassPic/{date}/{dir}",method = {RequestMethod.GET}) public void ProductClassPic(@PathVariable String date, @PathVariable String dir, HttpServletResponse response) throws BaseException, IOException { // 构建图片文件路径 String imagePath = "D:\\environment\\pic\\ProductClassPic\\"+date+"\\"+dir; File file = new File(imagePath); if (!file.exists()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Image not found"); return; } // 设置响应头 response.setContentType(MediaType.IMAGE_JPEG_VALUE); // 根据实际情况设置图片类型 response.setContentLength((int) file.length()); // 将文件内容写入响应流 Files.copy(file.toPath(), response.getOutputStream()); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界
2020-12-04 Layui多级表头导出
2020-12-04 Layui复杂表头自定义
2020-12-04 IDEA拉取分支项目
2020-12-04 Eclipse控制台乱码解决方法
2020-12-04 Oracel中空字符串转为0,null转为0处理方法