上传图片
public static String Img(MultipartFile file,HttpServletRequest servletRequest,int type,int width,int height){ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//获取当时时间 String img=df.format(new Date())+ StringUtils.right(file.getOriginalFilename(),4);//时间+图片的后四位 try { if(type==1) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(false).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //非等比例上传图片 }else if(type==2) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(true).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //等比例上传图片 }else { FileCopyUtils.copy(file.getBytes(), new File(servletRequest.getSession().getServletContext().getRealPath("/") + "image/" + img)); //等大小上传图片 } } catch (IOException e) { System.out.print(e+"图片上传失败!!"); } return "../image/"+img; }public static String Img(MultipartFile file,HttpServletRequest servletRequest,int type,int width,int height){ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//获取当时时间 String img=df.format(new Date())+ StringUtils.right(file.getOriginalFilename(),4);//时间+图片的后四位 try { if(type==1) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(false).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //非等比例上传图片 }else if(type==2) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(true).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //等比例上传图片 }else { FileCopyUtils.copy(file.getBytes(), new File(servletRequest.getSession().getServletContext().getRealPath("/") + "image/" + img)); //等大小上传图片 } } catch (IOException e) { System.out.print(e+"图片上传失败!!"); } return "../image/"+img; }public static String Img(MultipartFile file,HttpServletRequest servletRequest,int type,int width,int height){ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//获取当时时间 String img=df.format(new Date())+ StringUtils.right(file.getOriginalFilename(),4);//时间+图片的后四位 try { if(type==1) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(false).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //非等比例上传图片 }else if(type==2) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(true).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //等比例上传图片 }else { FileCopyUtils.copy(file.getBytes(), new File(servletRequest.getSession().getServletContext().getRealPath("/") + "image/" + img)); //等大小上传图片 } } catch (IOException e) { System.out.print(e+"图片上传失败!!"); } return "../image/"+img; }public static String Img(MultipartFile file,HttpServletRequest servletRequest,int type,int width,int height){ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//获取当时时间 String img=df.format(new Date())+ StringUtils.right(file.getOriginalFilename(),4);//时间+图片的后四位 try { if(type==1) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(false).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //非等比例上传图片 }else if(type==2) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(true).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //等比例上传图片 }else { FileCopyUtils.copy(file.getBytes(), new File(servletRequest.getSession().getServletContext().getRealPath("/") + "image/" + img)); //等大小上传图片 } } catch (IOException e) { System.out.print(e+"图片上传失败!!"); } return "../image/"+img; }public static String Img(MultipartFile file,HttpServletRequest servletRequest,int type,int width,int height){ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//获取当时时间 String img=df.format(new Date())+ StringUtils.right(file.getOriginalFilename(),4);//时间+图片的后四位 try { if(type==1) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(false).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //非等比例上传图片 }else if(type==2) { Thumbnails.of(file.getInputStream()).size(width, height).keepAspectRatio(true).toFile(servletRequest.getSession().getServletContext().getRealPath("/") + "zrch/image/" + img); //等比例上传图片 }else { FileCopyUtils.copy(file.getBytes(), new File(servletRequest.getSession().getServletContext().getRealPath("/") + "image/" + img)); //等大小上传图片 } } catch (IOException e) { System.out.print(e+"图片上传失败!!"); } return "../image/"+img; }