有了工具类之后,我们需要获取文件上传的inputStream
public void upload(MultipartFile myfiles,String url,String rootPath,CommonStuffModel commonStuffModel)throws Exception{ if(!myfiles.isEmpty()){ File localFile = new File(rootPath+url); File parentFile = localFile.getParentFile(); if(!parentFile.exists()){ parentFile.mkdirs(); } String contentType = myfiles.getContentType(); if(checkContainImgType(contentType)){//上传了图片类型附件 InputStream inputStream = myfiles.getInputStream(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(localFile)); WaterMarkUtils.setQrCodeForIMG(bos, inputStream, commonStuffModel,CommonFileUtil.loadFileType(contentType)); }else{ myfiles.transferTo(localFile); } } }ok,生成二维码水印