java itext后端生成pdf导出
public CustomApiResult<String> exportPdf(HttpServletRequest request, HttpServletResponse response) throws IOException {// 防止日志记录获取session异常request.getSession();// 设置编码格式response.setContentType("application/pdf;charset=UTF-8");response.setCharacterEncoding("utf-8");SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");String fileName = URLEncoder.encode("成品检验检验单" + dateFormat.format(new Date()), "UTF-8");response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".pdf");// 表头idString id = request.getParameter("id");// 分录idString taskEntryId = request.getParameter("entryId");
// 数据DynamicObject dynamicObject = getPdfData(Long.valueOf(id), Long.valueOf(taskEntryId));download(response, dynamicObject);return CustomApiResult.success("成功");}
画pdf
public void download(HttpServletResponse response, DynamicObject data) throws IOException {// 定义全局的字体静态变量Font headfont;Font content;// 最大宽度try {// 不同字体(这里定义为同一种字体:包含不同字号、不同style)BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);headfont = new Font(bfChinese, 14, Font.BOLD);content = new Font(bfChinese, 10, Font.NORMAL);BaseFont bf;Font font;//创建字体bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);//使用字体并给出颜色font = new Font(bf, 20, Font.BOLD, new Color(0, 0, 0));headfont = new Font(bf, 10, Font.BOLD, new Color(0, 0, 0));Document document = new Document(new RectangleReadOnly(842F, 595F));//设置页边距 60:左边距,60:右边距,72:上边距,72:下边距document.setMargins(60, 60, 72, 72);PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());//添加页码writer.setPageEvent(new PdfPageUtil());//打开生成的pdf文件document.open();//设置内容Paragraph paragraph = new Paragraph("成品检验 检验单", font);paragraph.setAlignment(1);//引用字体document.add(paragraph);// --------任务分录---设置表格的列宽和列数float[] widths = {25f, 25f, 25f, 25f, 25f, 25f};PdfPTable table = new PdfPTable(widths);table.setSpacingBefore(20f);// 设置表格宽度为100%table.setWidthPercentage(100.0F);table.setHeaderRows(1);table.getDefaultCell().setHorizontalAlignment(1);PdfPCell cell = null;//第一行table.addCell(createCenteredCell("检验标准", 30, null, headfont));table.addCell(createCenteredCell(data.getString("eo45_standard_name"), 0, null, content));table.addCell(createCenteredCell("检验日期", 0, null, headfont));table.addCell(createCenteredCell(String.valueOf(data.getDate("eo45_check_date")), 0, null, content));table.addCell(createCenteredCell("检验人员", 0, null, headfont));table.addCell(createCenteredCell(data.getString("eo45_check_person"), 0, null, content));// 第二行table.addCell(createCenteredCell("生产厂家", 30, null, headfont));table.addCell(createCenteredCell(data.getString("eo45_suppliers"), 0, null, content));table.addCell(createCenteredCell("物料名称", 0, null, headfont));table.addCell(createCenteredCell(data.getString("eo45_material_names"), 0, null, content));table.addCell(createCenteredCell("物料规格", 0, null, headfont));table.addCell(createCenteredCell(data.getString("eo45_specifications"), 0, null, content));//第三行table.addCell(createCenteredCell("物料批次", 30, null, headfont));table.addCell(createCenteredCell(data.getString("eo45_material_batch"), 0, null, content));table.addCell(createCenteredCell("总数量", 0, null, headfont));table.addCell(createCenteredCell(data.getString("eo45_total"), 0, null, content));table.addCell(createCenteredCell("", 0, null, headfont));table.addCell(createCenteredCell("", 0, null, content));// --------检验详情---设置表格的列宽和列数float[] widths2 = {25f, 25f, 25f, 25f, 25f, 25f, 25f};PdfPTable table2 = new PdfPTable(widths2);table2.setSpacingBefore(20f);// 设置表格宽度为100%table2.setWidthPercentage(100.0F);table2.setHeaderRows(1);table2.getDefaultCell().setHorizontalAlignment(1);// 第一行table2.addCell(createCenteredCell("序号", 30, new Color(204, 204, 204), headfont));table2.addCell(createCenteredCell("检验项目", 0, new Color(204, 204, 204), headfont));table2.addCell(createCenteredCell("标准要求", 0, new Color(204, 204, 204), headfont));table2.addCell(createCenteredCell("检验方法及依据", 0, new Color(204, 204, 204), headfont));table2.addCell(createCenteredCell("抽样数量", 0, new Color(204, 204, 204), headfont));table2.addCell(createCenteredCell("实测结果", 0, new Color(204, 204, 204), headfont));table2.addCell(createCenteredCell("检验判定", 0, new Color(204, 204, 204), headfont));// 第二行开始循环数据DynamicObjectCollection item = data.getDynamicObjectCollection("eo45_zjy_task_item");Iterator var8 = item.iterator();int i = 0;while (var8.hasNext()) {i++;DynamicObject itemData = (DynamicObject) var8.next();PdfPCell cell1 = new PdfPCell(new Paragraph(String.valueOf(i), content));PdfPCell cell2 = new PdfPCell(new Paragraph(itemData.getString("eo45_project"), content));PdfPCell cell3 = new PdfPCell(new Paragraph(itemData.getString("eo45_standard_require"), content));PdfPCell cell4 = new PdfPCell(new Paragraph(itemData.getString("eo45_test_method"), content));PdfPCell cell5 = new PdfPCell(new Paragraph(itemData.getString("eo45_sample_qty"), content));JSONObject jsonObject = StringUtils.isNotEmpty(itemData.getString("eo45_actual_json"))? JSONObject.parseObject(itemData.getString("eo45_actual_json")) : new JSONObject();PdfPCell cell6 = new PdfPCell(new Paragraph("", content));String type = jsonObject.containsKey("type") ? jsonObject.getString("type") : "";// 根据json类型解析数据if ("number".equals(type)) {cell6 = new PdfPCell(new Paragraph(jsonObject.containsKey("value") ? jsonObject.getString("value") : "", content));} else if ("select".equals(type)) {JSONArray jsonArray = jsonObject.containsKey("option") ? JSONArray.parseArray(jsonObject.getString("option")) : null;if (jsonArray != null) {for (int j = 0; j < jsonArray.size(); j++) {JSONObject jsonObject1 = jsonArray.getJSONObject(j);if (jsonObject1.containsKey("selectStatus") && jsonObject1.getBoolean("selectStatus")) {cell6 = new PdfPCell(new Paragraph(jsonObject.getString("eo45_value_mapping"), content));}}}} else {cell6 = new PdfPCell(new Paragraph(jsonObject.getString("eo45_actual_json"), content));}PdfPCell cell7 = new PdfPCell(new Paragraph(itemData.getString("eo45_item_decide"), content));//单元格对齐方式cell1.setHorizontalAlignment(Element.ALIGN_CENTER);cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);cell1.setFixedHeight(20);//单元格垂直对齐方式cell2.setHorizontalAlignment(Element.ALIGN_CENTER);cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);cell3.setHorizontalAlignment(Element.ALIGN_CENTER);cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);cell4.setHorizontalAlignment(Element.ALIGN_CENTER);cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);cell5.setHorizontalAlignment(Element.ALIGN_CENTER);cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);cell6.setHorizontalAlignment(Element.ALIGN_CENTER);cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);cell7.setHorizontalAlignment(Element.ALIGN_CENTER);cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);table2.addCell(cell1);table2.addCell(cell2);table2.addCell(cell3);table2.addCell(cell4);table2.addCell(cell5);table2.addCell(cell6);table2.addCell(cell7);}// ------综合判定----设置表格的列宽和列数// 设置表格的列宽和列数float[] widths3 = {25f, 75f};PdfPTable table3 = new PdfPTable(widths3);table3.setSpacingBefore(20f);// 设置表格宽度为100%table3.setWidthPercentage(100.0F);table3.setHeaderRows(1);table3.getDefaultCell().setHorizontalAlignment(1);cell = new PdfPCell(new Paragraph("综合判定", headfont));cell.setVerticalAlignment(Element.ALIGN_MIDDLE);cell.setHorizontalAlignment(Element.ALIGN_CENTER);cell.setFixedHeight(20);table3.addCell(cell);cell = new PdfPCell(new Paragraph(data.getString("eo45_decide"), content));cell.setVerticalAlignment(Element.ALIGN_MIDDLE);cell.setHorizontalAlignment(Element.ALIGN_CENTER);table3.addCell(cell);for (int j = 0; j < 1; j++) {PdfPCell cell1 = new PdfPCell(new Paragraph("备注", headfont));String contentResult = "";// 富文本处理if (StringUtils.isNotBlank(data.getString("eo45_decide_result"))) {org.jsoup.nodes.Document documentResult = Jsoup.parse(data.getString("eo45_decide_result"));contentResult = documentResult.text();}PdfPCell cell2 = new PdfPCell(new Paragraph(contentResult, content));//设置居中cell1.setHorizontalAlignment(Element.ALIGN_CENTER);cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);cell1.setFixedHeight(20);cell2.setHorizontalAlignment(Element.ALIGN_CENTER);cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);table3.addCell(cell1);table3.addCell(cell2);}document.add(table);document.add(table2);document.add(table3);//关闭文档document.close();} catch (DocumentException e) {log.error("导出pdf失败DocumentException:{}", e);} catch (Exception e) {log.error("导出pdf失败Exception:{}", e);}}private PdfPCell createCenteredCell(String value, float fixedHeight, Color color, Font font) {PdfPCell cell = new PdfPCell(new Paragraph(value, font));cell.setHorizontalAlignment(Element.ALIGN_CENTER);cell.setVerticalAlignment(Element.ALIGN_MIDDLE);// 设置背景色if (color != null) {cell.setBackgroundColor(color);}// 设置单元格高度if (fixedHeight != 0) {cell.setFixedHeight(fixedHeight);}return cell;}
工具类
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;import java.io.IOException;/*** @Author xx* @Date 2023/12/15 10:05* @Description: 导出pdf添加页数* @Version 1.0*/
public class PdfPageUtil extends PdfPageEventHelper {/*** 页眉*///public String header = "itext测试页眉";/*** 文档字体大小,页脚页眉最好和文本大小一致*/public int presentFontSize = 9;/*** 文档页面大小,最好前面传入,否则默认为A4纸张*/public Rectangle pageSize = PageSize.A4;// 模板public PdfTemplate total;// 基础字体对象public BaseFont bf = null;// 利用基础字体生成的字体对象,一般用于生成中文文字public Font fontDetail = null;/**** 无参构造方法.**/public PdfPageUtil() {}/**** 构造方法.** @param** @param presentFontSize* 数据体字体大小* @param pageSize* 页面文档大小,A4,A5,A6横转翻转等Rectangle对象*/public PdfPageUtil( int presentFontSize, Rectangle pageSize) {this.presentFontSize = presentFontSize;this.pageSize = pageSize;}public void setPresentFontSize(int presentFontSize) {this.presentFontSize = presentFontSize;}/**** 文档打开时创建模板*/@Overridepublic void onOpenDocument(PdfWriter writer, Document document) {// 共 页 的矩形的长宽高total = writer.getDirectContent().createTemplate(50, 50);}/****关闭每页的时候,写入页眉,写入'第几页共'这几个字。*/@Overridepublic void onEndPage(PdfWriter writer, Document document) {this.addPage(writer, document);}//加分页public void addPage(PdfWriter writer, Document document){//设置分页页眉页脚字体try {if (bf == null) {bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);}if (fontDetail == null) {fontDetail = new Font(bf, presentFontSize, Font.NORMAL);// 数据体字体}} catch (DocumentException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}// 1.写入页眉
// ColumnText.showTextAligned(writer.getDirectContent(),
// Element.ALIGN_LEFT, new Phrase(header, fontDetail),
// document.left(), document.top() + 20, 0);// 2.写入前半部分的 第 X页/共int pageS = writer.getPageNumber();//String foot1 = "第 " + pageS + " 页 /共";String foot1 = pageS +"/";Phrase footer = new Phrase(foot1, fontDetail);// 3.计算前半部分的foot1的长度,后面好定位最后一部分的'Y页'这俩字的x轴坐标,字体长度也要计算进去 = lenfloat len = bf.getWidthPoint(foot1, presentFontSize);// 4.拿到当前的PdfContentBytePdfContentByte cb = writer.getDirectContent();// 5.写入页脚1,x轴就是(右margin+左margin + right() -left()- len)/2.0FColumnText.showTextAligned(cb,Element.ALIGN_CENTER,footer,(document.rightMargin() + document.right()+ document.leftMargin() - document.left() - len) / 2.0F ,document.bottom() - 10, 0);cb.addTemplate(total, (document.rightMargin() + document.right()+ document.leftMargin() - document.left()) / 2.0F ,document.bottom() - 10); // 调节模版显示的位置}// //加水印
// public void addWatermark(PdfWriter writer){
// // 水印图片
// Image image;
// try {
// image = Image.getInstance("./web/images/001.jpg");
// PdfContentByte content = writer.getDirectContentUnder();
// content.beginText();
// // 开始写入水印
// for(int k=0;k<5;k++){
// for (int j = 0; j <4; j++) {
// image.setAbsolutePosition(150*j,170*k);
// content.addImage(image);
// }
// }
// content.endText();
// } catch (IOException | DocumentException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }/**** 关闭文档时,替换模板,完成整个页眉页脚组件*/@Overridepublic void onCloseDocument(PdfWriter writer, Document document) {// 关闭文档的时候,将模板替换成实际的 Y 值total.beginText();// 生成的模版的字体、颜色total.setFontAndSize(bf, presentFontSize);//页脚内容拼接 如 第1页/共2页//String foot2 = " " + (writer.getPageNumber()) + " 页";//页脚内容拼接 如 第1页/共2页String foot2 = String.valueOf(writer.getPageNumber() - 1);// 模版显示的内容total.showText(foot2);total.endText();total.closePath();}
}
相关文章:

java itext后端生成pdf导出
public CustomApiResult<String> exportPdf(HttpServletRequest request, HttpServletResponse response) throws IOException {// 防止日志记录获取session异常request.getSession();// 设置编码格式response.setContentType("application/pdf;charsetUTF-8")…...

信号-3-信号处理
main 信号捕捉的操作 sigaction struct sigaction OS不允许信号处理方法进行嵌套:某一个信号正在被处理时,OS会自动block改信号,之后会自动恢复 同理,sigaction.sa_mask 为捕捉指定信号后临时屏蔽的表 pending什么时候清零&…...
38配置管理工具(如Ansible、Puppet、Chef)
每天五分钟学Linux | 第三十八课:配置管理工具(如Ansible、Puppet、Chef) 大家好!欢迎再次来到我们的“每天五分钟学Linux”系列教程。在前面的课程中,我们学习了如何安装和配置邮件服务器。今天,我们将探…...
网络技术-定义配置ACL规则的语法和命令
定义ACL(访问控制列表)规则时,具体命令会根据所使用的设备和操作系统而有所不同。以下是一些常见的设备和操作系统中定义ACL规则的命令示例: 一:思科(Cisco)路由器/交换机 在思科设备中&#…...

动态规划一>子数组系列
题目: 2.解析: 代码: public int maxSubArray(int[] nums) {int n nums.length;int[] dp new int[n 1];int ret Integer.MIN_VALUE;for(int i 1; i < n; i){dp[i] Math.max(nums[i - 1], dp[i - 1] nums[i - 1]);ret Math.max(…...

一觉睡醒,全世界计算机水平下降100倍,而我却精通C语言——scanf函数
大家好啊,我是小象٩(๑ω๑)۶ 我的博客:Xiao Fei Xiangζั͡ޓއއ 很高兴见到大家,希望能够和大家一起交流学习,共同进步。* 这一节我们主要来学习scanf的基本用法,了解scanf返回值,懂得scanf占位符和…...

Altium Designer使用技巧(五)
一、敷铜(快捷键T-G-A) 1、工具栏点“设计”—>“规则”。 可以修改覆铜连线的宽度,也可以选择“直接连接”使得铜和网络节点完全相连。 这里方式有三种,可根据需要各个人习惯去设置。 2、敷铜与线全链接 (1)少量的话可右键“…...

Docker 的安装与使用
Docker 的安装 Docker 是一个开源的商业产品,有两个版本:社区版(Community Edition,缩写为 CE)和企业版(Enterprise Edition,缩写为 EE)。 Docker CE 的安装请参考官方文档…...
Android Studio 中三方库依赖无法找到的解决方案
目录 错误信息解析 解决方案 1. 检查依赖版本 2. 检查 Maven 仓库配置 3. 强制刷新 Gradle 缓存 4. 检查网络连接 5. 手动下载依赖 总结 相关推荐 最近,我在编译一个 Android 老项目时遇到了一个问题,错误信息显示无法找到 com.gyf.immersionba…...
PGMP练-DAY24
DAY241A program has completed and closed. The training for the receiving organization has also delivered. But the stakeholders still concern that the benefits cannot be realized in long term.What does the program manager review to improve the situation?项…...

【C++动态规划 最长公共子序列】1035. 不相交的线|1805
本文涉及知识点 C动态规划 LeetCode1035. 不相交的线 在两条独立的水平线上按给定的顺序写下 nums1 和 nums2 中的整数。 现在,可以绘制一些连接两个数字 nums1[i] 和 nums2[j] 的直线,这些直线需要同时满足: nums1[i] nums2[j] 且绘制的…...

FFmpeg的基本结构
FFmpeg框架可以简单分为两层,上层是以ffmpeg、ffplay、ffprobe为代表的命令行工具;其底层支撑是一些基础库,包含AVFormat、AVCodec、AVFilter、AVDevices、AVUtils等模块库。 常用函数如下: 1. AVFormat 封装/解封装模块 avf…...
react 受控组件和非受控组件
在 React 中,受控组件和非受控组件是两种处理表单元素(如输入框、选择框等)值的方式。 1. 受控组件 受控组件是指 React 组件的表单元素的值是由 React 组件的 state 来管理的。换句话说,React 会全程控制表单元素的值ÿ…...
C语言模块化概述
一、函数名的意义 1.c语言是一门面向过程的语言:所谓的过程就是动词,动作。 功能块动词1动词2……动词 2.功能块:就是一堆动词(动作)的组合,动作通过函数来实现。 3.函数的功能:承上启下 承…...
WPF 中的视觉层和逻辑层有什么区别?
在 WPF(Windows Presentation Foundation)中,视觉层和逻辑层是两个不同的概念,它们分别涉及到界面的展示和应用的行为。要理解这两个层次的区别,我们需要从 WPF 的设计背景、架构以及它们之间的相互关系来全面分析。 …...
Kafka简单实践
使用 Apache Kafka 和 Swoole 的 PHP 实践案例 一、引言 Apache Kafka 是一个开源的分布式流处理平台,能够处理大量的实时数据流。由于其高吞吐量、可扩展性和持久性,Kafka 成为构建微服务架构和大数据处理的重要工具。Swoole 是一个高性能的异步网络通…...
JS
文章目录 项目地址一、JS1.1 if语句1.2 for循环1.2 三元表达式1.3 switch1.4 数组的push方法1.5 fuction1.5.1 arguments1.6 匿名函数1.7 预解析1.8 js对象1.8.1创建一个类1.8.2 遍历对象1.9 js的内置对象1.9.1 随机整数二、DOM2.1 获取元素2.2 事件基础2.2.1 事件三要素2.2.2 …...

【原创】java+ssm+mysql商品库存管理系统(进销存)设计与实现
个人主页:程序猿小小杨 个人简介:从事开发多年,Java、Php、Python、前端开发均有涉猎 博客内容:Java项目实战、项目演示、技术分享 文末有作者名片,希望和大家一起共同进步,你只管努力,剩下的交…...

three.js 杂记
欧拉角旋转变换 x,y,z 弧度单位 THREE.MathUtils.DEG2RAD 度数转弧度 new THREE.Euler( - 90 * THREE.MathUtils.DEG2RAD, 0, 0 ) radius:半径 setFromSphericalCoords ( radius : Float, phi : Float, theta : Float ) : this 从球坐标中的radius、phi和theta设置该向量…...

基于Hadoop、hive的数仓搭建实践
文章目录 架构图Hadoop搭建Hive 搭建MySQL搭建官网文档下载配置配置hive环境变量配置日志文件配置hive-site 复制mysql 驱动包删除日志包初始化元数据启动metastore服务使用hive CLI启动hiveServer2访问hiveserver2客户端连接beeline shell连接 Dbeaver连接经验 基于HDFS Hive…...

微信小程序之bind和catch
这两个呢,都是绑定事件用的,具体使用有些小区别。 官方文档: 事件冒泡处理不同 bind:绑定的事件会向上冒泡,即触发当前组件的事件后,还会继续触发父组件的相同事件。例如,有一个子视图绑定了b…...
多场景 OkHttpClient 管理器 - Android 网络通信解决方案
下面是一个完整的 Android 实现,展示如何创建和管理多个 OkHttpClient 实例,分别用于长连接、普通 HTTP 请求和文件下载场景。 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas…...

SCAU期末笔记 - 数据分析与数据挖掘题库解析
这门怎么题库答案不全啊日 来简单学一下子来 一、选择题(可多选) 将原始数据进行集成、变换、维度规约、数值规约是在以下哪个步骤的任务?(C) A. 频繁模式挖掘 B.分类和预测 C.数据预处理 D.数据流挖掘 A. 频繁模式挖掘:专注于发现数据中…...

CMake基础:构建流程详解
目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

dedecms 织梦自定义表单留言增加ajax验证码功能
增加ajax功能模块,用户不点击提交按钮,只要输入框失去焦点,就会提前提示验证码是否正确。 一,模板上增加验证码 <input name"vdcode"id"vdcode" placeholder"请输入验证码" type"text&quo…...

【CSS position 属性】static、relative、fixed、absolute 、sticky详细介绍,多层嵌套定位示例
文章目录 ★ position 的五种类型及基本用法 ★ 一、position 属性概述 二、position 的五种类型详解(初学者版) 1. static(默认值) 2. relative(相对定位) 3. absolute(绝对定位) 4. fixed(固定定位) 5. sticky(粘性定位) 三、定位元素的层级关系(z-i…...
Qwen3-Embedding-0.6B深度解析:多语言语义检索的轻量级利器
第一章 引言:语义表示的新时代挑战与Qwen3的破局之路 1.1 文本嵌入的核心价值与技术演进 在人工智能领域,文本嵌入技术如同连接自然语言与机器理解的“神经突触”——它将人类语言转化为计算机可计算的语义向量,支撑着搜索引擎、推荐系统、…...

视频字幕质量评估的大规模细粒度基准
大家读完觉得有帮助记得关注和点赞!!! 摘要 视频字幕在文本到视频生成任务中起着至关重要的作用,因为它们的质量直接影响所生成视频的语义连贯性和视觉保真度。尽管大型视觉-语言模型(VLMs)在字幕生成方面…...
【RockeMQ】第2节|RocketMQ快速实战以及核⼼概念详解(二)
升级Dledger高可用集群 一、主从架构的不足与Dledger的定位 主从架构缺陷 数据备份依赖Slave节点,但无自动故障转移能力,Master宕机后需人工切换,期间消息可能无法读取。Slave仅存储数据,无法主动升级为Master响应请求ÿ…...

算法笔记2
1.字符串拼接最好用StringBuilder,不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...