/**
* @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());
}
}