Java 實現 文檔 添加 水印 工具類

一、pom 文件引用

<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.12.0</version></dependency><dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.14.3</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>ooxml-schemas</artifactId><version>1.0</version><exclusions><!--解決含嵌入文件ppt轉換報錯 ArrayStoreException--><exclusion><artifactId>xmlbeans</artifactId><groupId>org.apache.xmlbeans</groupId></exclusion></exclusions></dependency><dependency><groupId>com.itextpdf</groupId><artifactId>itext-asian</artifactId><version>5.2.0</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>2.0.16</version></dependency><dependency><groupId>com.itextpdf</groupId><artifactId>itextpdf</artifactId><version>5.5.13</version></dependency>

二、代碼展示

2.1,ImageUtil 圖片工具類

package cn.piesat.space.watermark.util;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;/*** @author: wangjing* @createTime: 2023-12-05 15:01* @version: 1.0.0* @Description: 圖片工具類*/
public class ImageUtil {/*** 調整圖片尺寸** @param inputPath 原圖片地址* @param outPath   新圖片地址* @param newWidth  新圖片寬* @param newHeight 新圖片高*/public static void resizeImage(String inputPath, String outPath, Integer newWidth, Integer newHeight) {try {BufferedImage bufferedImage = readPicture(inputPath);// 創建新的 BufferedImage,并設置繪制質量BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);Graphics2D g2d = resizedImage.createGraphics();g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);// 繪制原始圖像到新的 BufferedImage,并進行縮放Image scaledImage = bufferedImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);g2d.drawImage(scaledImage, 0, 0, null);g2d.dispose();// 保存新的圖片ImageIO.write(resizedImage, "jpg", new File(outPath));System.out.println("圖片尺寸調整完成!");} catch (IOException e) {e.printStackTrace();}}/*** 讀取圖片** @param path* @return*/public static BufferedImage readPicture(String path) {try {// 嘗試獲取本地return readLocalPicture(path);} catch (Exception e) {// 嘗試獲取網路return readNetworkPicture(path);}}/*** 讀取本地圖片** @param path* @return*/public static BufferedImage readLocalPicture(String path) {if (null == path) {throw new RuntimeException("本地圖片路徑不能為空");}// 讀取原圖片信息 得到文件File srcImgFile = new File(path);try {// 將文件對象轉化為圖片對象return ImageIO.read(srcImgFile);} catch (IOException e) {throw new RuntimeException(e);}}/*** 讀取網絡圖片** @param path 網絡圖片地址*/public static BufferedImage readNetworkPicture(String path) {if (null == path) {throw new RuntimeException("網絡圖片路徑不能為空");}try {// 創建一個URL對象,獲取網絡圖片的地址信息URL url = new URL(path);// 將URL對象輸入流轉化為圖片對象 (url.openStream()方法,獲得一個輸入流)BufferedImage bugImg = ImageIO.read(url.openStream());if (null == bugImg) {throw new RuntimeException("網絡圖片地址不正確");}return bugImg;} catch (IOException e) {throw new RuntimeException(e);}}
}

2.1,DocumentWaterMarkUtils?文檔水印工具類

package cn.piesat.space.watermark.util;import cn.piesat.space.watermark.enums.WatermarkTypeEnum;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.pdf.*;
import com.microsoft.schemas.vml.CTShape;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFHeader;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.xmlbeans.XmlObject;import javax.imageio.ImageIO;
import javax.swing.*;
import javax.xml.namespace.QName;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.lang.reflect.Field;/*** @author: wangjing* @createTime: 2023-12-05 15:01* @version: 1.0.0* @Description: 文檔水印工具類*/
@Slf4j
public class DocumentWaterMarkUtils {/*** 水印默認字體*/private static Font defaultFont = new Font("宋體", Font.PLAIN, 70);/*** 水印默認字體顏色*/private static Color defaultColor = new Color(0, 0, 0, 60);/*** 水印透明度*/private static float alpha = 0.5f;/*** 水印之間的間隔*/private static final int xMove = 200;/*** 水印之間的間隔*/private static final int yMove = 200;public static void main(String[] args) {String watermarkText = "測試水印";String watermarkImage = "/Users/wangjing/Desktop/watermark/test.jpeg";// pdfString pdfInputPath = "/Users/wangjing/Desktop/watermark/pdf/test.pdf";String pdfOutPath = "/Users/wangjing/Desktop/watermark/pdf/test2.pdf";addPdfWatermark(pdfInputPath, pdfOutPath, watermarkText);// pptString pptInputPath = "/Users/wangjing/Desktop/watermark/ppt/test.pptx";// excel 文字水印String pptOutPath = "/Users/wangjing/Desktop/watermark/ppt/test2.pptx";addPPTWatermark(pptInputPath, pptOutPath, 1, watermarkText, defaultFont, defaultColor);// excel 圖片水印String pptOutPathImage = "/Users/wangjing/Desktop/watermark/ppt/test3.pptx";addPPTWatermark(pptInputPath, pptOutPathImage, 2, watermarkImage, null, null);// excelString watermarkImageExcel = "/Users/wangjing/Desktop/watermark/image/test1.jpg";String excelInputPath = "/Users/wangjing/Desktop/watermark/excel/test.xlsx";// excel 文字水印String excelOutPath = "/Users/wangjing/Desktop/watermark/excel/test2.xlsx";addExcelWatermark(excelInputPath, excelOutPath, 1, watermarkText, defaultFont, defaultColor);// excel 圖片水印String excelOutPathImage = "/Users/wangjing/Desktop/watermark/excel/test3.xlsx";addExcelWatermark(excelInputPath, excelOutPathImage, 2, watermarkImageExcel, null, null);//word 添加文字水印String wordInputPath = "/Users/wangjing/Desktop/watermark/word/test.docx";String wordOutPath = "/Users/wangjing/Desktop/watermark/word/test2.docx";addWordWatermark(wordInputPath, wordOutPath, watermarkText, "#D3D3D3", true, false);}/*** pdf設置文字水印** @param inputPath* @param outPath* @param watermark*/public static void addPdfWatermark(String inputPath, String outPath, String watermark) {// 創建輸出文件File file = new File(outPath);if (!file.exists()) {try {file.createNewFile();} catch (IOException e) {log.error("addPdfWatermark fail: 創建輸出文件IO異常", e);throw new RuntimeException("addPdfWatermark fail: 創建輸出文件IO異常");}}BufferedOutputStream outBufferedOutputStream = null;try {outBufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));} catch (FileNotFoundException e) {log.error("addPdfWatermark fail: 源文件不存在", e);throw new RuntimeException("addPdfWatermark fail: 源文件不存在");}PdfStamper pdfStamper = null;int total = 0;PdfContentByte content;com.itextpdf.text.Rectangle pageSizeWithRotation = null;BaseFont base = null;PdfReader inputPdfReader = null;try {inputPdfReader = new PdfReader(inputPath);// 解決PdfReader not opened with owner passwordField f = PdfReader.class.getDeclaredField("ownerPasswordUsed");f.setAccessible(true);f.set(inputPdfReader, Boolean.TRUE);pdfStamper = new PdfStamper(inputPdfReader, outBufferedOutputStream);total = inputPdfReader.getNumberOfPages() + 1;base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);} catch (IOException e) {log.error("addPdfWatermark fail:", e);throw new RuntimeException("addPdfWatermark fail:IOException");} catch (DocumentException e) {log.error("addPdfWatermark fail:", e);throw new RuntimeException("addPdfWatermark fail: DocumentException");} catch (IllegalAccessException e) {e.printStackTrace();} catch (NoSuchFieldException e) {e.printStackTrace();}// 獲取水印文字的高度和寬度Integer textH = 0;Integer textW = 0;JLabel label = new JLabel();label.setText(watermark);FontMetrics metrics = label.getFontMetrics(label.getFont());textH = metrics.getHeight();textW = metrics.stringWidth(label.getText());PdfGState gs = new PdfGState();for (Integer i = 1; i < total; i++) {//在內容上方加水印content = pdfStamper.getOverContent(i);gs.setFillOpacity(alpha);content.saveState();content.setGState(gs);content.beginText();content.setFontAndSize(base, 20);// 獲取每一頁的高度、寬度pageSizeWithRotation = inputPdfReader.getPageSizeWithRotation(i);float pageHeight = pageSizeWithRotation.getHeight();float pageWidth = pageSizeWithRotation.getWidth();// 根據紙張大小多次添加, 水印文字成30度角傾斜for (int height = -5 + textH; height < pageHeight; height = height + yMove) {for (int width = -5 + textW; width < pageWidth + textW; width = width + xMove) {content.showTextAligned(Element.ALIGN_LEFT, watermark, width - textW, height - textH, 30);}}content.endText();}// 管理所有流try {pdfStamper.close();outBufferedOutputStream.flush();outBufferedOutputStream.close();inputPdfReader.close();} catch (IOException e) {log.error("addPdfWatermark fail:", e);throw new RuntimeException("addPdfWatermark fail: 關閉流異常,IOException");} catch (DocumentException e) {log.error("addPdfWatermark fail:", e);throw new RuntimeException("addPdfWatermark fail: 關閉流異常,DocumentException");}}/*** PPT 添加水印** @param inputPath     原ppt地址* @param targetpath    新ppt地址* @param watermarkType 水印類型(1:文字水印;2:圖片水印)* @param watermark     水印* @param font          字體* @param color         顏色*/public static void addPPTWatermark(String inputPath, String targetpath, Integer watermarkType, String watermark,Font font, Color color) {XMLSlideShow slideShow = null;try {slideShow = new XMLSlideShow(new FileInputStream(inputPath));} catch (IOException e) {log.error("addPPTWatermark fail:", e);throw new RuntimeException("addPPTWatermark fail: 獲取PPT文件失敗");}ByteArrayOutputStream os = null;FileOutputStream out = null;try {//獲取水印os = getWatermarkImage(watermarkType, watermark, font, color, 1280, 720);PictureData pictureData = slideShow.addPicture(os.toByteArray(), PictureData.PictureType.PNG);for (XSLFSlideMaster xslfSlideMaster : slideShow.getSlideMasters()) {XSLFPictureShape pictureShape = xslfSlideMaster.createPicture(pictureData);
//                pictureShape.setAnchor(new java.awt.Rectangle(0, 0, -1 , -1));pictureShape.setAnchor(pictureShape.getAnchor());}out = new FileOutputStream(targetpath);slideShow.write(out);} catch (IOException e) {log.error("addPPTWatermark fail:" + e);throw new RuntimeException("addPPTWatermark fail: 生成ppt文件失敗");} finally {if (slideShow != null) {try {slideShow.close();} catch (IOException e) {e.printStackTrace();}}if (out != null) {try {out.close();} catch (IOException e) {e.printStackTrace();}}if (os != null) {try {os.close();} catch (IOException e) {e.printStackTrace();}}}}/*** excel 添加水印** @param inputPath     原excel地址* @param outPath       新excel地址* @param watermarkType 水印類型:1:文本水印;2:圖片水印;* @param watermark     水印(文字或圖片URL)* @param font          字體* @param color         顏色*/public static void addExcelWatermark(String inputPath, String outPath, Integer watermarkType, String watermark,Font font, Color color) {//讀取excel文件XSSFWorkbook workbook = null;try {workbook = new XSSFWorkbook(new FileInputStream(inputPath));} catch (FileNotFoundException e) {log.error("addExcelWaterMark fail: 源文件不存在", e);throw new RuntimeException("addExcelWaterMark fail: 源文件不存在");} catch (IOException e) {log.error("addExcelWaterMark fail: 讀取源文件IO異常", e);throw new RuntimeException("addExcelWaterMark fail: 讀取源文件IO異常");}OutputStream fos = null;ByteArrayOutputStream os = new ByteArrayOutputStream();try {//獲取水印os = getWatermarkImage(watermarkType, watermark, font, color, 1000, 800);int pictureIdx = workbook.addPicture(os.toByteArray(), Workbook.PICTURE_TYPE_PNG);// 獲取每個Sheet表for (int i = 0; i < workbook.getNumberOfSheets(); i++) {XSSFSheet xssfSheet = workbook.getSheetAt(i);String rID =xssfSheet.addRelation(null, XSSFRelation.IMAGES, workbook.getAllPictures().get(pictureIdx)).getRelationship().getId();xssfSheet.getCTWorksheet().addNewPicture().setId(rID);}// Excel文件生成后存儲的位置。File file = new File(outPath);fos = new FileOutputStream(file);workbook.write(fos);} catch (Exception e) {log.error("addExcelWaterMark fail: 創建輸出文件IO異常", e);throw new RuntimeException("addExcelWaterMark fail: 創建輸出文件IO異常");} finally {if (os != null) {try {os.close();} catch (IOException e) {e.printStackTrace();}}if (fos != null) {try {fos.close();} catch (IOException e) {e.printStackTrace();}}if (workbook != null) {try {workbook.close();} catch (IOException e) {e.printStackTrace();}}}}/*** word 添加文字水印** @param inputPath      原文件地址* @param outPath        新文件地址* @param watermark      水印文字* @param watermarkColor 水印字體顏色* @param incline        是否傾斜(true 傾斜,false 不傾斜)* @param readable       是否設置僅可讀(true 僅可讀,false 可編輯)*/public static void addWordWatermark(String inputPath, String outPath, String watermark, String watermarkColor,Boolean incline, Boolean readable) {// 根據URL 獲取 XWPFDocument 對象XWPFDocument xwpfDocument = null;try {xwpfDocument = new XWPFDocument(new FileInputStream(new File(inputPath)));} catch (FileNotFoundException fileNotFoundException) {log.error("addWordWaterMark fail: ", fileNotFoundException);throw new RuntimeException("addWordWaterMark fail: 源文件不存在");} catch (IOException ioException) {log.error("addWordWaterMark fail: ", ioException);throw new RuntimeException("addWordWaterMark fail: 讀取源文件IO異常");} catch (Exception exception) {log.error("addWordWaterMark fail: ", exception);throw new RuntimeException("addWordWaterMark fail: 不支持的文檔格式");}XWPFHeaderFooterPolicy headerFooterPolicy = xwpfDocument.getHeaderFooterPolicy();if (headerFooterPolicy == null) {//兼容處理headerFooterPolicy = xwpfDocument.createHeaderFooterPolicy();}//調用API添加水印,效果不好為水平居中headerFooterPolicy.createWatermark(watermark);//處理后續文檔更新水印邏輯XWPFHeader xwpfHeader = headerFooterPolicy.getHeader(XWPFHeaderFooterPolicy.DEFAULT);XWPFParagraph xwpfParagraph = xwpfHeader.getParagraphArray(0);//設置水印樣式和位置,保持傾斜角度更好看和實用xwpfParagraph.getCTP().newCursor();XmlObject[] xmlobjects = xwpfParagraph.getCTP().getRArray(0).getPictArray(0).selectChildren(new QName("urn:schemas-microsoft-com:vml", "shape"));if (xmlobjects.length > 0) {CTShape ctshape = (CTShape) xmlobjects[0];// 水印字體顏色ctshape.setFillcolor(watermarkColor);// 水印是否傾斜if (incline) {ctshape.setStyle(ctshape.getStyle() + ";rotation:315");}}// 設置文檔只讀if (readable) {xwpfDocument.enforceReadonlyProtection();}File file = new File(outPath);if (!file.exists()) {try {file.createNewFile();} catch (IOException e) {log.error("addWordWaterMark fail: 創建輸出文件IO異常", e);throw new RuntimeException("addWordWaterMark fail: 創建輸出文件失敗");}}try {xwpfDocument.write(new FileOutputStream(outPath));} catch (FileNotFoundException e) {log.error("addWordWaterMark fail: 輸出文件不存在", e);throw new RuntimeException("addWordWaterMark fail: 創建輸出文件失敗");} catch (IOException e) {log.error("addWordWaterMark fail: ", e);throw new RuntimeException("addWordWaterMark fail");} finally {if (xwpfDocument != null) {try {xwpfDocument.close();} catch (IOException e) {e.printStackTrace();}}}}/*** 獲取水印圖片文件流** @param watermarkType 水印類型(1:文字水印;2:圖片水印)* @param watermark     水印* @param font          字體* @param color         顏色* @param width         圖片寬* @param height        圖片高* @return*/private static ByteArrayOutputStream getWatermarkImage(Integer watermarkType, String watermark, Font font,Color color, Integer width, Integer height) {ByteArrayOutputStream os = new ByteArrayOutputStream();try {// 導出到字節流BBufferedImage bufferedImage = null;if (WatermarkTypeEnum.TEXT_WATERMARK.getCode().equals(watermarkType)) {bufferedImage = createWaterMarkImageBig(watermark, font, color, width, height);} else {// 圖片水印bufferedImage = ImageUtil.readPicture(watermark);}ImageIO.write(bufferedImage, "png", os);} catch (IOException e) {log.error("testToImage fail: 創建水印圖片IO異常", e);throw new RuntimeException("testToImage fail: 創建水印圖片IO異常");}return os;}/*** 根據文字生成水印圖片(大號 平鋪)** @param text  文本文字* @param font  字體* @param color 顏色* @return*/public static BufferedImage createWaterMarkImageBig(String text, Font font, Color color, Integer width,Integer height) {// 獲取bufferedImage對象BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Graphics2D g2d = image.createGraphics();image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);g2d.dispose();g2d = image.createGraphics();//設置字體顏色和透明度g2d.setColor(color);//設置字體g2d.setStroke(new BasicStroke(1));//設置字體類型  加粗 大小g2d.setFont(font);//設置傾斜度g2d.rotate(Math.toRadians(-30), (double) image.getWidth() / 2, (double) image.getHeight() / 2);FontRenderContext context = g2d.getFontRenderContext();Rectangle2D bounds = font.getStringBounds(text, context);double x = (width - bounds.getWidth()) / 2;double y = (height - bounds.getHeight()) / 2;double ascent = -bounds.getY();double baseY = y + ascent;//寫入水印文字原定高度過小,所以累計寫水印,增加高度g2d.drawString(text, (int) x, (int) baseY);//設置透明度g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));//釋放對象g2d.dispose();return image;}}

三、效果展示

3.1,word 水印

3.2,excel 水印

3.2.1,文字水印

3.2.2,圖片水印

3.3,ppt 水印

3.3.1,文字水印

3.3.2,圖片水印

3.4,PDF 水印

注:以上內容僅提供參考和交流,請勿用于商業用途,如有侵權聯系本人刪除!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/214064.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/214064.shtml
英文地址,請注明出處:http://en.pswp.cn/news/214064.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

MeterSphere實戰(一)

MeterSphere是一位朋友講到的測試平臺&#xff0c;說這東西是開源的&#xff0c;因為我是做測試的&#xff0c;很樂意了解一些新鮮事物。在我看來&#xff0c;測試就是要專注一些領域&#xff0c;然后要啥都會一點點&#xff0c;接著融會貫通起來&#xff0c;這樣就可以萬變不離…

C語言--不使用庫函數,把一個數字轉為字符串【詳細解釋】

一.題目描述 輸入一個數字&#xff0c;把他轉為字符串 比如&#xff1a;輸入數字&#xff1a;12345 輸出&#xff1a;12345&#xff08;這里的12345是字符串12345&#xff09; 二.思路分析 比如給定一個數字12345&#xff0c;先把它轉為字符54321&#xff08;“54321”&#…

線程互斥與同步

用戶級線程 內核的LWP Linux線程 OS概念中經常說的 用戶級線程 和 內核級線程 也就是線程實現真的是在OS內部實現&#xff0c;還是應用層或用戶層實現 很明顯Linux是屬于用戶級線程 用戶級執行流&#xff08;用戶級線程&#xff09; &#xff1a;內核lwp 1 : 1 也有1&…

驍龍8 Gen 3 vs A17 Pro

驍龍8 Gen 3 vs A17 Pro——誰會更勝一籌&#xff1f; Geekbench、AnTuTu 和 3DMark 等基準測試在智能手機領域發揮著至關重要的作用。它們為制造商和手機愛好者提供了設備性能的客觀衡量標準。這些測試有助于評估難以測量的無形方面。然而&#xff0c;值得注意的是&#xff0c…

騷操作:NanoDrop測蛋白濃度

?大家好&#xff0c;最近實驗室的BCA儀器壞了&#xff0c;偶然發現nanodrop也可以測蛋白濃度&#xff0c;省不少時間&#xff01;本方法原理是&#xff1a;紫外吸收 友情提示&#xff1a;由于表格的存在&#xff0c;用電腦看本推文&#xff0c;效果更好 紫外吸收法 較為靈…

31條PCB設計布線技巧:

大家在做PCB設計時&#xff0c;都會發現布線這個環節必不可少&#xff0c;而且布線的合理性&#xff0c;也決定了PCB的美觀度和其生產成本的高低&#xff0c;同時還能體現出電路性能和散熱性能的好壞&#xff0c;以及是否可以讓器件的性能達到最優等。 本篇內容&#xff0c;將…

分布式鎖實現方案 - Lock4j 使用

一、Lock4j 分布式鎖工具 你是不是在使用分布式鎖的時候&#xff0c;還在自己用 AOP 封裝框架&#xff1f;那么 Lock4j 你可以考慮一下。 Lock4j 是一個分布式鎖組件&#xff0c;其提供了多種不同的支持以滿足不同性能和環境的需求。 立志打造一個簡單但富有內涵的分布式鎖組…

Redis分布式緩存超詳細總結!

文章目錄 前言一、Redis持久化解決數據丟失問題1.RDB&#xff08;Redis Database Backup file&#xff09;持久化&#xff08;1&#xff09;執行RDB&#xff08;2&#xff09;RDB方式bgsave的基本流程&#xff08;3&#xff09;RDB會在什么時候執行&#xff1f;save 60 1000代表…

VBA信息獲取與處理:在EXCEL中隨機函數的利用

《VBA信息獲取與處理》教程(版權10178984)是我推出第六套教程&#xff0c;目前已經是第一版修訂了。這套教程定位于最高級&#xff0c;是學完初級&#xff0c;中級后的教程。這部教程給大家講解的內容有&#xff1a;跨應用程序信息獲得、隨機信息的利用、電子郵件的發送、VBA互…

RabbitMQ學習

一、RabbitMQ 采用 AMQP 高級消息隊列協議的一種消息隊列技術,最大的特點就是消費并不需要確保提供方存在,實現了服務之間的高度解耦 1、在分布式系統下具備異步,削峰,負載均衡等一系列高級功能; 2、擁有持久化的機制&#xff0c;進程消息&#xff0c;隊列中的信息也可以保存下…

計算機網絡(三) | 數據鏈路層 PPP協議、廣播CSMA/CD協議、集線器、交換器、擴展and高速以太網

文章目錄 1 數據鏈路基本概念和問題1.1 基本概念1.2 基本問題&#xff08;1&#xff09;封裝成幀&#xff08;2&#xff09;透明傳輸&#xff08;3&#xff09;差錯控制 2.數據鏈路層協議2.1 點對點 PPP協議2.1.1 需要實現的2.1.2 PPP組成2.1.3 幀格式2.1.4 工作流程 2.2 廣播 …

內網穿透的應用-如何結合Cpolar內網穿透工具實現在IDEA中遠程訪問家里或者公司的數據庫

文章目錄 1. 本地連接測試2. Windows安裝Cpolar3. 配置Mysql公網地址4. IDEA遠程連接Mysql小結 5. 固定連接公網地址6. 固定地址連接測試 IDEA作為Java開發最主力的工具&#xff0c;在開發過程中需要經常用到數據庫&#xff0c;如Mysql數據庫&#xff0c;但是在IDEA中只能連接本…

配置BFD多跳檢測示例

BFD簡介 定義 雙向轉發檢測BFD&#xff08;Bidirectional Forwarding Detection&#xff09;是一種全網統一的檢測機制&#xff0c;用于快速檢測、監控網絡中鏈路或者IP路由的轉發連通狀況。 目的 為了減小設備故障對業務的影響&#xff0c;提高網絡的可靠性&#xff0c;網…

“==”和“equals”的區別

“”和“equals”的區別 Java中“”和“equals”的區別在于&#xff0c;它們比較的內容不同。""比較的是對象的引用是否相等&#xff0c;而equals比較的是對象的值是否相等。 具體來說&#xff0c;以下是兩個操作符之間的區別&#xff1a; “”比較的是對象的引用&…

【鏈表Linked List】力扣-117 填充每個節點的下一個右側節點指針II

目錄 問題描述 解題過程 官方題解 問題描述 給定一個二叉樹&#xff1a; struct Node {int val;Node *left;Node *right;Node *next; } 填充它的每個 next 指針&#xff0c;讓這個指針指向其下一個右側節點。如果找不到下一個右側節點&#xff0c;則將 next 指針設置為 N…

C++中字符串詳解

在C語言中只能通過字符串數組來模擬字符串&#xff0c;沒有字符串類型。在C引入了string類來表示字符串類型。從而用它定義字符串。 在C語言中&#xff1a; char str[] "abc"; char str[] {a&#xff0c;b,c,\0}; char* str "abc"; //這三種形式是C語言…

因為高考考砸了,我學了計算機

2015年&#xff0c;是我高中的最后一年。 2023年&#xff0c;我已在計算機領域工作十多個年頭。 我出生在東部省份的一個不沿海小縣城&#xff0c;在那里度過了我高考前的17年。起點平平&#xff0c;沒有任何特長傍身&#xff0c;也可以說是毫無亮點&#xff1b;成績中等&#…

代碼隨想錄算法訓練營第四十五天 _ 動態規劃_ 70. 爬樓梯、322.零錢兌換、279.完全平方數、139.單詞拆分。

學習目標&#xff1a; 動態規劃五部曲&#xff1a; ① 確定dp[i]的含義 ② 求遞推公式 ③ dp數組如何初始化 ④ 確定遍歷順序 ⑤ 打印遞歸數組 ---- 調試 引用自代碼隨想錄&#xff01; 60天訓練營打卡計劃&#xff01; 學習內容&#xff1a; 70. 爬樓梯 動態規劃五步曲&…

中文語音標注工具FunASR(語音識別)

全稱 A Fundamental End-to-End Speech Recognition Toolkit&#xff08;一個語音識別工具&#xff09; 可能大家用過whisper&#xff08;openAi&#xff09;&#xff0c;它【標注英語的確很完美】&#xff0c;【但中文會出現標注錯誤】或搞了個沒說的詞替換上去&#xff0c;所…

【Fiddler】IDEA配置Fiddler

由于遇上了個迷之請求&#xff0c;接口調用正常&#xff0c;OkHttpClient調用正常&#xff0c;RestTemplate調用失敗&#xff0c;所以想看看發送的報文是怎樣的&#xff0c;所以就下了個Fiddler 問題 下載安裝&#xff0c;以及如何安裝證書&#xff0c;網上太多相同文章了&…