原文:http://stackoverflow.com/questions/5690228/spring-mvc-how-to-return-image-in-responsebody/28548701
@RequestMapping(value = "/getImage.do")
@ResponseBody
public void getImage(HttpServletResponse response) {
response.setContentType("image/jpeg");
String filePath = "D:\\temp\\upload-images\\1.jpg";
File file = new File(filePath);
InputStream in = null;
try {
in = new FileInputStream(file);
try {
IOUtils.copy(in, response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}