国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽

這篇具有很好參考價值的文章主要介紹了微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

前言

圖片上傳和預(yù)覽在移動端應(yīng)用非常廣泛和頻繁,vant組件庫van-uploader組件已經(jīng)幫我們實現(xiàn)了大部分功能,但是在系統(tǒng)中頻繁使用還是有點麻煩,我們根據(jù)自身的業(yè)務(wù)系統(tǒng)重新封裝了一下簡化我們的開發(fā)。后端使用springboot集成jcifs實現(xiàn)文件管理微服務(wù)。

附件上傳

微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽

附件預(yù)覽

微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽

前端組件

組件介紹

前端只要在視圖中使用組件,傳入需要的參數(shù)即可

businessid 業(yè)務(wù)id,用于把業(yè)務(wù)單號和附件關(guān)聯(lián)
tmp_id 臨時業(yè)務(wù)id,在一開始業(yè)務(wù)單號未產(chǎn)生的時候和附件關(guān)聯(lián)
name 用于把不通類型的附件歸類到不同的文件夾
businesstype 用于區(qū)分同一個業(yè)務(wù)單號下不通類型的附件組
readonly 判斷組件是預(yù)覽還是上傳
<bdog-uploader-image      
	id="visit_uploader"
	businessid="{{id}}"
	tmp_id="{{tmp_id}}"
	name="customerVisit"
	businesstype="visit"
    readonly ="{{readonly}}"
/>  

組件js部分代碼

const util = require('../../utils/util.js')
var request = require('../../utils/request.js')
var { config } = require('../../utils/config.js')
import Toast from '@vant/weapp/toast/toast';
const app = getApp();

Component({
  properties: {
    businessid: {
      type: String
    },
    tmp_id: {
        type: String
    },
    name: {
        type: String
    },
    businesstype: {
        type: String
    },
    readonly:{
        type:Boolean
    }
  },
  data: {
    fileList: [],
  },
  attached:function(){
    //this.getFileList()
  },
  methods: {
     afterRead(event) {
        Toast.loading({
            duration: 0, // 持續(xù)展示 toast
            forbidClick: true,
            message: "上傳中"
        })
        var that = this
        const { file } = event.detail
        wx.uploadFile({
          url: config.baseUrl +'/MpAttachment/uploadFile', 
          filePath: file.url,
          name: 'file',
          header: {
            "Content-Type": "multipart/form-data",
            "id":that.data.businessid,
            "tmpId":that.data.tmp_id,
            "name":that.data.name,
            "businesstype":that.data.businesstype,
            "token":app.globalData.userInfo.token,
          },
          success(res) {
            const data = JSON.parse(res.data)
            if(data.code == 200){
                // 上傳完成需要更新 fileList
                const { fileList = [] } = that.data;
                const url = config.baseUrl +'/MpAttachment/getImage?id=' + data.data.id
                fileList.push({ ...file, url: url, id: data.data.id })
                that.setData({ fileList })
                Toast.clear();
                Toast({ type: 'success',message: '上傳成功',duration:500, })
            }else{
                Toast({ type: 'fail',message: '上傳失敗',duration:500, })
            }
          },
          fail:function(res){
            Toast({ type: 'fail',message: '上傳失敗',duration:500, })
          }
        });
      },
      delete(event) {
        Toast.loading({
            duration: 0, // 持續(xù)展示 toast
            forbidClick: true,
            message: "刪除中"
        })
        var that = this
        var data = {}
        data['id'] = event.detail.file.id
        request.get('/MpAttachment/delete',data)
        .then(function (res) {
          if(res.code == 200){
            const { fileList } = that.data;
            const newFileList = fileList.filter((items) =>{
              return items.id != event.detail.file.id
            })
            that.setData({ fileList : newFileList, })
            Toast.clear();
            Toast({ type: 'success',message: '刪除成功',duration:500, })
          }else{
            Toast({ type: 'fail',message: '刪除失敗',duration:500, })
          }
        }, function (error) {
            Toast({ type: 'fail',message: '刪除失敗',duration:500, })
        })
      },
      getFileList() {
        var that = this
        var data = {}
        data['businessid'] = that.data.businessid
        data['businesstype'] = that.data.businesstype
        request.get('/MpAttachment/getList',data)
        .then(function (res) {
          if(res.code == 200){
            const fileList = res.data;
            fileList.forEach(function(items){
                items.url = config.baseUrl + '/MpAttachment/getImage?id=' + items.id
                items.type = 'image'
            })
            that.setData({ fileList : fileList, })
          }else{
            Toast({ type: 'fail',message: '附件加載失敗',duration:500, })
          }
        }, function (error) {
            Toast({ type: 'fail',message: '附件加載失敗',duration:500, })
        })
      }
  }

})

組件視圖部分代碼

<van-cell title="" >
    <van-uploader
        slot="right-icon"
        file-list="{{ fileList }}"
        max-count="9"
        bind:after-read="afterRead"
        bind:delete="delete"  
        show-upload="{{ !readonly }}"
        deletable="{{ !readonly }}"
    />
</van-cell>
<van-toast id="van-toast" />

后端微服務(wù)

后端微服務(wù)

微服務(wù)總歸包含了附件上傳、刪除、獲取圖片、獲取列表、附件上傳個服務(wù)

???????微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽

?

?微服務(wù)代碼

@RestController
@RequestMapping("/MpAttachment")
@Api(tags = { Swagger2Config.TAG_MpAttachment })
public class MpAttachmentController implements ServletContextAware {

    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;
    protected ServletContext servletContext;
    String FileConnect ="/";
    @Autowired
    protected UserService userService;
    @Autowired
    @Qualifier("dispJdbcTemplate")
    protected JdbcTemplate dispJdbcTemplate;
    @Autowired
    protected MpAttachmentService mpAttachmentService;


    @ApiOperation(value = "獲取列表", notes = "")
    @GetMapping(value="/getList")
    public Result getList(@ApiParam(value = "businessid" , required=true ) @RequestParam String businessid,
                          @ApiParam(value = "businesstype" , required=false ) @RequestParam String businesstype) throws ParseException {
        List list =  mpAttachmentService.getViewList(businessid,businesstype);
        return Result.success(list,"成功!");
    }

    @CrossOrigin
    @ApiOperation(value = "附件上傳", notes = "")
    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestParam("file") MultipartFile file, @RequestHeader("name") String name, @RequestHeader String id, @RequestHeader String tmpId, @RequestHeader String businesstype) {
        if (file.isEmpty()) {
            return Result.failed("上傳文件為空");
        }
        String uuid = UUID.randomUUID().toString();
        // 獲取文件名
        String fileName = file.getOriginalFilename();
        String newFileName = uuid + "."+ fileName.split("\\.")[1];
        MpAttachment attachment = new MpAttachment();
        attachment.setBusinessid(id);
        attachment.setTmp_businessid(tmpId);
        attachment.setBusinesstype(businesstype);
        attachment.setFilename(fileName);
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyMMdd");
        String uploadPath = name + FileConnect + LocalDate.now().format(fmt);
        attachment.setFilepath(uploadPath + FileConnect + newFileName);

        try {
            //文件上傳
            SmbFileUtils.save(file.getBytes(),uploadPath,newFileName);
            attachment.setCreatetime(DateUtils.getNow());
            attachment.setId(UUID.randomUUID().toString());
            mpAttachmentService.add(attachment);
            return Result.success(mpAttachmentService.getView(attachment.getId()),"成功!");
        } catch (IOException e) {
            e.printStackTrace();
            return Result.failed("文件上傳失敗");
        }
    }

    @CrossOrigin
    @ApiOperation(value = "附件上傳并添加水印", notes = "")
    @PostMapping("/uploadImageFile")
    public Result uploadImageFile(@RequestParam("file") MultipartFile file, @RequestHeader("name") String name, @RequestHeader String id, @RequestHeader String tmpId, @RequestHeader String businesstype) {
        User user = userService.findCueernt();
        if (file.isEmpty()) {
            return Result.failed("上傳文件為空");
        }
        String uuid = UUID.randomUUID().toString();
        // 獲取文件名
        String fileName = file.getOriginalFilename();
        String newFileName = uuid + "."+ fileName.split("\\.")[1];
        MpAttachment attachment = new MpAttachment();
        attachment.setBusinessid(id);
        attachment.setTmp_businessid(tmpId);
        attachment.setBusinesstype(businesstype);
        attachment.setFilename(fileName);
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyMMdd");
        String uploadPath = name + FileConnect + LocalDate.now().format(fmt);
        attachment.setFilepath(uploadPath + FileConnect + newFileName);

        try {
            //添加水印
            InputStream input = new ByteArrayInputStream((file.getBytes()));
            /**給圖片添加文字水印**/
            ArrayList<String> watermarkList =new ArrayList<String>();
            watermarkList.add("現(xiàn)場拍照[客戶照片]");
            watermarkList.add(user.getName() +" " + DateUtils.dateToStr(new Date(),"yyyy-MM-dd HH:mm"));
            InputStream output = ImageWatermarkUtils.markImageByText(watermarkList,input,fileName.split("\\.")[1]);
            //文件上傳
            SmbFileUtils.save(FileUtils.StreamToByte(output),uploadPath,newFileName);
            attachment.setCreatetime(DateUtils.getNow());
            attachment.setId(UUID.randomUUID().toString());
            mpAttachmentService.add(attachment);
            return Result.success(mpAttachmentService.getView(attachment.getId()),"成功!");
        } catch (IOException e) {
            e.printStackTrace();
            return Result.failed("文件上傳失敗");
        }
    }


    @CrossOrigin
    @ApiOperation(value = "base64附件上傳", notes = "")
    @PostMapping("/base64UploadFile")
    public Result base64UploadFile(@RequestBody String base64Image, @RequestHeader("fileName") String fileName, @RequestHeader("name") String name, @RequestHeader String id, @RequestHeader String tmpId, @RequestHeader String businesstype) throws UnsupportedEncodingException {
        String uuid = UUID.randomUUID().toString();
        base64Image = java.net.URLDecoder.decode(base64Image,"UTF-8");
        fileName = java.net.URLDecoder.decode(fileName,"UTF-8");
        id = java.net.URLDecoder.decode(id,"UTF-8");
        String newFileName = uuid + "."+ fileName.split("\\.")[1];
        MpAttachment attachment = new MpAttachment();
        attachment.setBusinessid(id);
        attachment.setTmp_businessid(tmpId);
        attachment.setBusinesstype(businesstype);
        attachment.setFilename(fileName);
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyMMdd");
        String uploadPath = name + FileConnect + LocalDate.now().format(fmt);
        attachment.setFilepath(uploadPath + FileConnect + newFileName);

        try {

            byte[] imageByte = ImageUtils.base64ImageToByte(base64Image);
            SmbFileUtils.save(imageByte,uploadPath,newFileName);
            attachment.setCreatetime(DateUtils.getNow());
            attachment.setId(UUID.randomUUID().toString());
            mpAttachmentService.add(attachment);
            return Result.success(mpAttachmentService.getView(attachment.getId()),"成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed("文件上傳失敗");
        }
    }

    @ApiOperation(value = "獲取圖片", notes = "")
    @GetMapping(value="/getImage", produces = {MediaType.IMAGE_PNG_VALUE})
    public BufferedImage getImage(@ApiParam(value = "id" , required=true ) @RequestParam String id) throws IOException {
        MpAttachment attachment = mpAttachmentService.get(id);
        if(attachment !=null)
        {
            InputStream imageInputStream =  SmbFileUtils.getFile(attachment.getFilepath());
            return ImageIO.read(imageInputStream);
        }
        return null;
    }

    @ApiOperation(value = "刪除", notes = "")
    @GetMapping(value="/delete")
    public Result delete(@ApiParam(value = "id" , required=true ) @RequestParam String id) {
        MpAttachment attachment = mpAttachmentService.get(id);
        try {
            SmbFileUtils.delete(attachment.getFilepath());
            int result = mpAttachmentService.delete(id);
            if(result >0){
                return Result.success(attachment,"刪除成功!");
            }else {
                return Result.success(attachment,"刪除失?。?);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed("失敗");
        }

    }


    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response){
        this.request = request;
        this.response = response;
        this.session = request.getSession();
    }
    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }
}

jcifs文件管理幫助類

package com.brickdog.common.utils;


import jcifs.CIFSContext;
import jcifs.CIFSException;
import jcifs.context.SingletonContext;
import jcifs.smb.*;

import java.io.*;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Objects;


public class SmbFileUtils {
    static String ip = "127.0.0.1";
    static String domain = "127.0.0.1/upload";
    static String userName = "admin";
    static String password = "admin";

    static void SmbFileUtils(){

    }
    //根據(jù)賬號密碼登錄
    private static CIFSContext withNTLMCredentials(CIFSContext ctx) {
        return ctx.withCredentials(new NtlmPasswordAuthenticator(domain,
                userName, password));
    }

    //保存文件
    public static String save(byte[] byteArr, String url,String fileName) throws IOException {
        InputStream in = new ByteArrayInputStream(byteArr);
        String status = "";
        try {
            CIFSContext context = withNTLMCredentials(SingletonContext.getInstance());
            SmbFileWriter.createDirectory("smb://" + domain  +"/" + url, context);
            boolean result = SmbFileWriter.writeSmbFile(in, "smb://" + domain  +"/" + url +"/" + fileName, context);
            status = "success";
        } catch (Exception e) {
            e.printStackTrace();
            status = "error";
        } finally {
            in.close();
            return status;
        }
    }
    //獲取文件
    public static  InputStream getFile(String filePath) throws IOException {
        String url = "smb://" + domain + "/" + filePath;

        try {
            CIFSContext context = withNTLMCredentials(SingletonContext.getInstance());
            SmbFileReader reader = new SmbFileReader();
            byte[] byteArr = reader.readSmbFile(url, context);
            InputStream input = new ByteArrayInputStream(byteArr);
            return  input;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    //刪除文件
    public static String delete(String filePath) throws IOException {
        String status = "";
        String url = "smb://" + domain + "/" + filePath;

        try {
            CIFSContext context = withNTLMCredentials(SingletonContext.getInstance());
            SmbFile file = new SmbFile(url, context);
            if (file.exists()) {
                file.delete();
                status = "success";
            }
        } catch (Exception e) {
            e.printStackTrace();
            status = "error";
        }
        return status;
    }

    static class SmbFileReader {
        public byte[] readSmbFile(String path, CIFSContext context) throws IOException {
            try  {
                SmbFile smbFile = new SmbFile(path, context);
                long fileSize = smbFile.length();
                if (fileSize > Integer.MAX_VALUE) {
                    System.out.println("file too big...");
                    return null;
                }
                InputStream fi = smbFile.getInputStream();
                byte[] buffer = new byte[(int) fileSize];
                int offset = 0;
                int numRead = 0;
                while (offset < buffer.length
                        && (numRead = fi.read(buffer, offset, buffer.length - offset)) >= 0) {
                    offset += numRead;
                }
                // 確保所有數(shù)據(jù)均被讀取
                if (offset != buffer.length) {
                    throw new IOException("Could not completely read file "
                            + smbFile.getName());
                }
                fi.close();
                return buffer;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    static class SmbFileWriter {
        static boolean writeSmbFile(String source, String target, CIFSContext context) throws IOException {
            if (StrUtils.isEmpty(source) || StrUtils.isEmpty(target)) {
                return false;
            }
            return writeSmbFile(Files.newInputStream(Paths.get(source)),
                    target, context);
        }

        static boolean writeSmbFile(InputStream in, String target, CIFSContext context) throws IOException {
            if (Objects.nonNull(in) && StrUtils.isNotEmpty(target)) {
                try (SmbFile file = new SmbFile(target, context)) {
                    try (SmbFile parent = new SmbFile(file.getParent(), context)) {
                        if (!parent.exists()) {
                            createDirectory(file.getParent(), context);
                        }
                        if (!file.exists()) {
                            file.createNewFile();
                        }
                    }
                    try (OutputStream os = file.getOutputStream()) {
                        byte[] bytes = new byte[1024];
                        while (in.read(bytes) != -1) {
                            os.write(bytes);
                        }
                        return true;
                    }
                }finally {
                    in.close();
                }
            }
            return false;
        }

        static SmbFile createDirectory(String targetDir, CIFSContext context) throws MalformedURLException,
                CIFSException, MalformedURLException {
            try (SmbFile dir = new SmbFile(targetDir, context)) {
                if (!dir.exists()) {
                    dir.mkdir();
                }
                return dir;
            }
        }
    }
}

pom文件

這邊jcifs包我們一定要使用2.0以上的,2.0以下經(jīng)常會出現(xiàn)網(wǎng)盤權(quán)限認證卡住導致讀取或者上傳附件特別慢

<dependency>
    <groupId>eu.agno3.jcifs</groupId>
    <artifactId>jcifs-ng</artifactId>
    <version>2.1.3</version>
</dependency>

生成文件

我們對每類文件進行文件加歸類,每天一個文件夾分開存放附件

微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽

?表結(jié)構(gòu)

微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽

添加水印

微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽

使用案列

//添加水印
InputStream input = new ByteArrayInputStream((file.getBytes()));
/**給圖片添加文字水印**/
ArrayList<String> watermarkList =new ArrayList<String>();
watermarkList.add("現(xiàn)場拍照[客戶照片]");
watermarkList.add(user.getName() +" " + DateUtils.dateToStr(new Date(),"yyyy-MM-dd HH:mm"));
InputStream output = ImageWatermarkUtils.markImageByText(watermarkList,input,fileName.split("\\.")[1]);
//文件上傳
SmbFileUtils.save(FileUtils.StreamToByte(output),uploadPath,newFileName);

圖片幫助類

package com.brickdog.common.utils;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;

/**
 * 圖片添加水印工具類
 * 文字水印 圖片水印 利用jdk ,不依賴第三方
 */
public class ImageWatermarkUtils {

    static final String NEW_IMAGE_NAME_PRE_STR = "_water";
    // 水印透明度
    private static float alpha = 0.5f;
    // 水印文字字體
    private static Font font = new Font("宋體", Font.BOLD, 12);
    // 水印文字顏色
    private static Color color = Color.white;


    /**
     * 給圖片添加水印、可設(shè)置水印圖片旋轉(zhuǎn)角度
     *
     * @param iconPath   水印圖片路徑
     * @param srcImgPath 源圖片路徑
     * @param targerPath 目標圖片路徑
     * @param degree     水印圖片旋轉(zhuǎn)角度
     */
    public static void markImageByIcon(String iconPath, String srcImgPath, String targerPath, Integer degree) {
        OutputStream os = null;
        try {
            if (StrUtils.isBlank(targerPath)) {
                targerPath = srcImgPath.substring(0, srcImgPath.lastIndexOf(".")) + NEW_IMAGE_NAME_PRE_STR + srcImgPath.substring(srcImgPath.lastIndexOf("."));
            }
            Image srcImg = ImageIO.read(new File(srcImgPath));
            BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null), srcImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
            // 得到畫筆對象
            // Graphics g= buffImg.getGraphics();
            Graphics2D g = buffImg.createGraphics();

            // 設(shè)置對線段的鋸齒狀邊緣處理
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

            g.drawImage(srcImg.getScaledInstance(srcImg.getWidth(null), srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);

            if (null != degree) {
                // 設(shè)置水印旋轉(zhuǎn)
                g.rotate(Math.toRadians(degree),
                        (double) buffImg.getWidth() / 2, (double) buffImg
                                .getHeight() / 2);
            }
            // 水印圖象的路徑 水印一般為gif或者png的,這樣可設(shè)置透明度
            ImageIcon imgIcon = new ImageIcon(iconPath);
            // 得到Image對象。
            Image img = imgIcon.getImage();
            float alpha = 1f; // 透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
            /**
             * 以下一算水印圖位置,右下角
             */
            int width = srcImg.getWidth(null);
            int height = srcImg.getHeight(null);
            int iconWidth = img.getWidth(null);
            int iconHeight = img.getHeight(null);
            int x = width - iconWidth;
            int y = height - iconHeight;
            x = x < 0 ? 0 : x;
            y = y < 0 ? 0 : y;
            // 表示水印圖片的位置
            g.drawImage(img, x, y, null);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
            g.dispose();
            os = new FileOutputStream(targerPath);
            // 生成圖片
            ImageIO.write(buffImg, "JPG", os);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != os)
                    os.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 給圖片添加水印文字、可設(shè)置水印文字的旋轉(zhuǎn)角度
     *
     */
    public static InputStream markImageByText(ArrayList<String> watermarkList, InputStream imageInputStream,String formatName) {

        try {

            // 1、源圖片
            Image srcImg = ImageIO.read(imageInputStream);
            int srcImgWidth = srcImg.getWidth(null);
            int srcImgHeight = srcImg.getHeight(null);
            BufferedImage buffImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB);

            // 2、得到畫筆對象
            Graphics2D g = buffImg.createGraphics();
            // 3、設(shè)置對線段的鋸齒狀邊緣處理
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g.drawImage(
                    srcImg.getScaledInstance(srcImg.getWidth(null),
                            srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);
            // 4、設(shè)置黑色遮罩
            int rowHeight = 20;
            int padding = 6;
            int height = rowHeight * watermarkList.size() + padding;
            int x = padding;
            int y = srcImgHeight - height;
            g.setColor(Color.black);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.3f));
            g.fillRect(0,y,srcImgWidth,height);

            // 5、設(shè)置水印文字顏色
            g.setColor(color);
            // 6、設(shè)置水印文字Font
            g.setFont(font);
            // 7、設(shè)置水印文字透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1f));
            // 8、第一參數(shù)->設(shè)置的內(nèi)容,后面兩個參數(shù)->文字在圖片上的坐標位置(x,y)
            for(int i=0;i<watermarkList.size();i++)
            {
               g.drawString(watermarkList.get(i), x, y + rowHeight);
               y =y+rowHeight;
            }
            // 9、釋放資源
            g.dispose();
            // 10、生成圖片
            ByteArrayOutputStream os = new ByteArrayOutputStream();

            ImageIO.write(buffImg, formatName, os);
            InputStream  outStream = new ByteArrayInputStream(os.toByteArray());

            return  outStream;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {

            } catch (Exception e) {
                e.printStackTrace();
            }
            try {

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return  null;
    }

    /**
     * 獲取水印文字總長度
     *
     * @param waterMarkContent
     *            水印的文字
     * @param g
     * @return 水印文字總長度
     */
    private static int getWatermarkLength(String waterMarkContent, Graphics2D g) {
        return g.getFontMetrics(g.getFont()).charsWidth(waterMarkContent.toCharArray(), 0, waterMarkContent.length());
    }

}

參考文獻

https://github.com/codelibs/jcifs
https://github.com/xuanyiying/jcifs-ng-smb2-demo文章來源地址http://www.zghlxwxcb.cn/news/detail-488661.html

到了這里,關(guān)于微信小程序基于vant和springboot實現(xiàn)附件上傳和預(yù)覽的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • vant-uploader多附件上傳

    vant-uploader多附件上傳

    問題一:部分安卓機只有相機和錄音選項,沒有相冊選項。 解決:accept=“image/*” 問題二:移動端上組件只能上傳圖片,沒有文件管理選項,不能上傳其他文件類型(pdf, docx等) 解決:accept=“” // 不限制上傳的文件類型

    2024年02月11日
    瀏覽(12)
  • 基于Springboot實現(xiàn)微信小程序(后端)

    基于Springboot實現(xiàn)微信小程序(后端)

    ? MyBatis Framework , MySQL Driver , Lombok 以及, Spring Web WXCrawlingService是為了實現(xiàn)其他功能 ? 后端其實較為簡單,只需要把前端請求的數(shù)據(jù)給前端就好了,不用做過多的數(shù)據(jù)處理: DocController: DocServiceImpl: mapper: pojo中的Doc: 1. 進入頁面時發(fā)起網(wǎng)絡(luò)請求 1.1 基本信息 請求路徑:/g

    2024年04月13日
    瀏覽(27)
  • 基于SpringBoot+Vue+uniapp微信小程序的微信小程序書店的詳細設(shè)計和實現(xiàn)

    基于SpringBoot+Vue+uniapp微信小程序的微信小程序書店的詳細設(shè)計和實現(xiàn)

    ?? 博主介紹 :?全網(wǎng)粉絲10W+,CSDN特邀作者、博客專家、CSDN新星計劃導師、全棧領(lǐng)域優(yōu)質(zhì)創(chuàng)作者,博客之星、掘金/華為云/阿里云/InfoQ等平臺優(yōu)質(zhì)作者、專注于Java、小程序技術(shù)領(lǐng)域和畢業(yè)項目實戰(zhàn)??? ???? 精彩專欄 推薦訂閱 ???? 2023-2024年最值得選的微信小程序畢業(yè)設(shè)

    2024年03月17日
    瀏覽(98)
  • 基于Springboot+Mybatis+微信小程序?qū)崿F(xiàn)小型運動管理平臺

    基于Springboot+Mybatis+微信小程序?qū)崿F(xiàn)小型運動管理平臺

    此文主要功能包括:運動健康平臺登錄注冊、了解健康知識、查看管理運動的文章與詳情、每日登錄打卡、系統(tǒng)通知、留言管理、提交運動功能。使用Java作為后端語言進行支持,界面友好,開發(fā)簡單。 2.1、下載安裝IntelliJ IDEA(后端語言開發(fā)工具),Mysql數(shù)據(jù)庫,微信Web開發(fā)者工

    2024年02月02日
    瀏覽(21)
  • 基于SpringBoot+Vue+uniapp微信小程序的校園反詐騙微信小程序的詳細設(shè)計和實現(xiàn)

    基于SpringBoot+Vue+uniapp微信小程序的校園反詐騙微信小程序的詳細設(shè)計和實現(xiàn)

    ?? 博主介紹 :?全網(wǎng)粉絲10W+,CSDN特邀作者、博客專家、CSDN新星計劃導師、全棧領(lǐng)域優(yōu)質(zhì)創(chuàng)作者,博客之星、掘金/華為云/阿里云/InfoQ等平臺優(yōu)質(zhì)作者、專注于Java、小程序技術(shù)領(lǐng)域和畢業(yè)項目實戰(zhàn)??? ???? 精彩專欄 推薦訂閱 ???? 2023-2024年最值得選的微信小程序畢業(yè)設(shè)

    2024年03月22日
    瀏覽(26)
  • 基于Java+SpringBoot+微信小程序?qū)崿F(xiàn)奶茶點單系統(tǒng)

    基于Java+SpringBoot+微信小程序?qū)崿F(xiàn)奶茶點單系統(tǒng)

    再不用擔心逢年過節(jié)的第一杯奶茶有沒有人送了,制作一個奶茶點單系統(tǒng)自己當?shù)曛?,開懷暢飲,一勞永逸。 精彩專欄持續(xù)更新,收藏訂閱不迷路↓↓↓ 微信小程序?qū)崙?zhàn)開發(fā)專欄

    2023年04月09日
    瀏覽(29)
  • 基于微信小程序+Springboot校園二手商城系統(tǒng)設(shè)計和實現(xiàn)

    基于微信小程序+Springboot校園二手商城系統(tǒng)設(shè)計和實現(xiàn)

    博主介紹 : ? 全網(wǎng)粉絲30W+,csdn特邀作者、博客專家、CSDN新星導師、Java領(lǐng)域優(yōu)質(zhì)創(chuàng)作者,博客之星、掘金/華為云/阿里云/InfoQ等平臺優(yōu)質(zhì)作者、目前 專注于大學生項目實戰(zhàn)開發(fā),講解,畢業(yè)答疑輔導 ? ?? 文末獲取源碼聯(lián)系 ?? ?????精彩專欄 推薦訂閱 ?????不然下次找不到

    2024年02月11日
    瀏覽(18)
  • 基于SpringBoot+微信小程序汽車服務(wù)系統(tǒng)的設(shè)計與實現(xiàn)

    基于SpringBoot+微信小程序汽車服務(wù)系統(tǒng)的設(shè)計與實現(xiàn)

    早晨四點起來,開發(fā)個基于SpringBoot+微信小程序汽車服務(wù)系統(tǒng)。 困死我了。 送完孩子,然后去上班。 昨天有個讀者朋友問小孟:程序員之間的差距為何如此之大。 有時候甚至在同一所大學,同一個專業(yè),有的學生大四畢業(yè)可以拿到四五十w的年薪,有的學生畢業(yè)找不到工作。

    2024年02月03日
    瀏覽(16)
  • 基于SpringBoot+Vue校園導航微信小程序的設(shè)計與實現(xiàn)

    基于SpringBoot+Vue校園導航微信小程序的設(shè)計與實現(xiàn)

    博主主頁: 一季春秋 博主簡介: 專注Java技術(shù)領(lǐng)域和畢業(yè)設(shè)計項目實戰(zhàn)、Java、微信小程序、安卓等技術(shù)開發(fā),遠程調(diào)試部署、代碼講解、文檔指導、ppt制作等技術(shù)指導。 主要內(nèi)容: SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、Python、小程序、安卓app、大數(shù)據(jù)等設(shè)計與開發(fā)。 感興

    2024年03月12日
    瀏覽(28)
  • 基于SpringBoot微信小程序的寵物美容預(yù)約系統(tǒng)設(shè)計與實現(xiàn)

    基于SpringBoot微信小程序的寵物美容預(yù)約系統(tǒng)設(shè)計與實現(xiàn)

    博主介紹 : ? 全網(wǎng)粉絲30W+,csdn特邀作者、博客專家、CSDN新星計劃導師、Java領(lǐng)域優(yōu)質(zhì)創(chuàng)作者,博客之星、掘金/華為云/阿里云/InfoQ等平臺優(yōu)質(zhì)作者、專注于Java技術(shù)領(lǐng)域和學生畢業(yè)項目實戰(zhàn),高校老師/講師/同行交流合作 ? 主要內(nèi)容: SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、P

    2024年02月03日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包