- @TokenIgnore
- @RequestMapping(value = "/avatar/{fileName}")
- public void getAvatar(@PathVariable("fileName") String fileName,HttpServletResponse response) throws IOException {
- String path=pathTool.getUserAvatarPath()+fileName;
- OutputStream os = null;
- InputStream is = null;
- try {
- String contentType="";
- String ext="";
- if(fileName.endsWith("jpg")) {
- contentType="image/jpeg";
- ext="jpg";
- }else if(fileName.endsWith("png")) {
- contentType="image/png";
- ext="png";
- }else if(fileName.endsWith("gif")) {
- contentType="image/gif";
- ext="gif";
- }
- is=new FileInputStream(new File(path));
- BufferedImage image = ImageIO.read(is);
- response.setContentType(contentType);
- os = response.getOutputStream();
- if (image != null) {
- ImageIO.write(image,ext, os);
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (is != null) {
- is.close();
- }
- if (os != null) {
- os.flush();
- os.close();
- }
- }
- }