当前位置: 首页 > news >正文

word poi-tl 图表功能增强,插入图表折线图、柱状图、饼状图

目录

    • 问题
      • 解决问题
      • poi-tl介绍
    • 功能实现
      • 引入依赖
      • 功能介绍
    • 功能实例
      • 饼图
        • 模版
        • 代码
        • 效果图
      • 雷达图(模版同饼图)
        • 代码
        • 效果图
      • 柱状图(模版同饼图)
        • 代码
        • 效果图
    • 附加
      • CustomCharts 工具类
      • CustomChartSingleSeriesRenderData 数据对象
      • CustomChartRenderPolicy 插件类

问题

由于在开发功能需求中,word文档需要根据数据动态生成图表,不同的数据类型生成不同的图表信息,而word模版引擎原有功能只能做替换,不满足需求;

解决问题

  • 目前选择的poi-tl的模版引擎,在原有的基础上新增自定义插件来实现功能

poi-tl介绍

poi-tl 是一个基于Apache POI的Word模板引擎,也是一个免费开源的Java类库,你可以非常方便的加入到你的项目中;

Word模板引擎功能描述
文本将标签渲染为文本
图片将标签渲染为图片
表格将标签渲染为表格
图表条形图(3D条形图)、柱形图(3D柱形图)、面积图(3D面积图)、折线图(3D折线图)、雷达图、饼图(3D饼图)、散点图等图表渲染
If Condition判断根据条件隐藏或者显示某些文档内容(包括文本、段落、图片、表格、列表、图表等)
Foreach Loop循环根据集合循环某些文档内容(包括文本、段落、图片、表格、列表、图表等)
Loop表格行循环复制渲染表格的某一行
Loop表格列循环复制渲染表格的某一列
Loop有序列表支持有序列表的循环,同时支持多级列表
Highlight代码高亮word中代码块高亮展示,支持26种语言和上百种着色样式
Markdown将Markdown渲染为word文档
Word批注完整的批注功能,创建批注、修改批注等
Word附件Word中插入附件
SDT内容控件内容控件内标签支持
Textbox文本框文本框内标签支持
图片替换将原有图片替换成另一张图片
书签、锚点、超链接支持设置书签,文档内锚点和超链接功能
Expression Language完全支持SpringEL表达式,可以扩展更多的表达式:OGNL, MVEL
样式支持有序列表的循环,同时支持多级列表
模板嵌套模板包含子模板,子模板再包含子模板
模板嵌套模板包含子模板,子模板再包含子模板
合并Word合并Merge,也可以在指定位置进行合并
用户自定义函数(插件)插件化设计,在文档任何位置执行函数

功能实现

引入依赖

		<dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.12.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-full</artifactId><version>5.2.5</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.5</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.2.5</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.25</version></dependency><!-- spring el表达式 --><dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>5.3.18</version></dependency>

功能介绍

  • 目前支持的图表类型有饼图、柱形图、面积图、折线图、雷达图等
  • 同时支持添加到表格一起渲染

功能实例

饼图

模版

![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/53b227ba4eca4923871b3f526f6784dd.png

代码
    @Testpublic void test() throws Exception {Configure config = Configure.builder().addPlugin('&',new CustomChartRenderPolicy()).useSpringEL(false).build();Map<String,Object> dataMap = new HashMap<String, Object>();CustomChartSingleSeriesRenderData chartSingleSeriesRenderData = CustomCharts.ofPie("日期", new String[]{"2024-01", "2024-02", "2024-03", "2024-04", "2024-05", "2024-06","2024-07", "2024-08", "2024-09", "2024-10", "2024-11", "2024-12"}).series("数值", new Integer[]{10, 35, 21, 46, 79, 55,39, 32, 71, 28, 22, 11}).setWidthAndHeight(10,10).create();dataMap.put("testChars", chartSingleSeriesRenderData);ClassPathResource classPathResource = new ClassPathResource("static/word/template.docx");try (InputStream resourceInputStream = classPathResource.getInputStream();XWPFTemplate template = XWPFTemplate.compile(resourceInputStream,config);){template.render(dataMap);template.writeAndClose(new FileOutputStream("output.docx"));} catch (Exception e) {e.printStackTrace();}}
效果图

在这里插入图片描述

雷达图(模版同饼图)

代码
 @Testpublic void test() throws Exception {Configure config = Configure.builder().addPlugin('&',new CustomChartRenderPolicy()).useSpringEL(false).build();Map<String,Object> dataMap = new HashMap<String, Object>();CustomChartSingleSeriesRenderData chartSingleSeriesRenderData = CustomCharts.ofRadar("日期", new String[]{"2024-01", "2024-02", "2024-03", "2024-04", "2024-05", "2024-06","2024-07", "2024-08", "2024-09", "2024-10", "2024-11", "2024-12"}).series("数值", new Integer[]{10, 35, 21, 46, 79, 55,39, 32, 71, 28, 22, 11}).setWidthAndHeight(10,10).create();dataMap.put("testChars", chartSingleSeriesRenderData);ClassPathResource classPathResource = new ClassPathResource("static/word/template.docx");try (InputStream resourceInputStream = classPathResource.getInputStream();XWPFTemplate template = XWPFTemplate.compile(resourceInputStream,config);){template.render(dataMap);template.writeAndClose(new FileOutputStream("output.docx"));} catch (Exception e) {e.printStackTrace();}}
效果图

在这里插入图片描述

柱状图(模版同饼图)

代码
 @Testpublic void test() throws Exception {Configure config = Configure.builder().addPlugin('&',new CustomChartRenderPolicy()).useSpringEL(false).build();Map<String,Object> dataMap = new HashMap<String, Object>();CustomChartSingleSeriesRenderData chartSingleSeriesRenderData = CustomCharts.ofBar("日期", new String[]{"2024-01", "2024-02", "2024-03", "2024-04", "2024-05", "2024-06","2024-07", "2024-08", "2024-09", "2024-10", "2024-11", "2024-12"}).series("数值", new Integer[]{10, 35, 21, 46, 79, 55,39, 32, 71, 28, 22, 11}).setWidthAndHeight(10,10).create();dataMap.put("testChars", chartSingleSeriesRenderData);ClassPathResource classPathResource = new ClassPathResource("static/word/template.docx");try (InputStream resourceInputStream = classPathResource.getInputStream();XWPFTemplate template = XWPFTemplate.compile(resourceInputStream,config);){template.render(dataMap);template.writeAndClose(new FileOutputStream("output.docx"));} catch (Exception e) {e.printStackTrace();}}
效果图

在这里插入图片描述

附加

CustomCharts 工具类


import com.deepoove.poi.data.RenderData;
import com.deepoove.poi.data.RenderDataBuilder;
import com.deepoove.poi.data.SeriesRenderData;
import org.apache.poi.xddf.usermodel.chart.ChartTypes;public class CustomCharts {public static CustomCharts.ChartSingles ofArea(String chartTitle, String[] categories) {return ofSingleSeries(chartTitle, categories, ChartTypes.AREA);}public static CustomCharts.ChartSingles ofRadar(String chartTitle, String[] categories) {return ofSingleSeries(chartTitle, categories, ChartTypes.RADAR);}public static CustomCharts.ChartSingles ofLine(String chartTitle, String[] categories) {return ofSingleSeries(chartTitle, categories, ChartTypes.LINE);}public static CustomCharts.ChartSingles ofBar(String chartTitle, String[] categories) {return ofSingleSeries(chartTitle, categories, ChartTypes.BAR);}public static CustomCharts.ChartSingles ofPie(String chartTitle, String[] categories) {return ofSingleSeries(chartTitle, categories, ChartTypes.PIE);}public static CustomCharts.ChartSingles ofPie3D(String chartTitle, String[] categories) {return ofSingleSeries(chartTitle, categories, ChartTypes.PIE3D);}public static CustomCharts.ChartSingles ofDoughnut(String chartTitle, String[] categories) {return ofSingleSeries(chartTitle, categories, ChartTypes.DOUGHNUT);}public static CustomCharts.ChartSingles ofSingleSeries(String chartTitle, String[] categories, ChartTypes chartTypes) {return new CustomCharts.ChartSingles(chartTitle, categories, chartTypes);}public static interface ChartSetting<T extends RenderData> {CustomCharts.ChartBuilder<T> setxAsixTitle(String xAxisTitle);CustomCharts.ChartBuilder<T> setyAsixTitle(String yAxisTitle);}public static abstract class ChartBuilder<T extends RenderData> implements RenderDataBuilder<T>, CustomCharts.ChartSetting<T> {protected String chartTitle;protected String xAxisTitle;protected String yAxisTitle;protected String[] categories;protected ChartTypes chartTypes;protected ChartBuilder(String chartTitle, String[] categories, ChartTypes chartTypes) {this.chartTitle = chartTitle;this.categories = categories;this.chartTypes = chartTypes;}protected void checkLengh(int length) {if (categories.length != length) {throw new IllegalArgumentException("The length of categories and series values in chart must be the same!");}}public CustomCharts.ChartBuilder<T> setxAsixTitle(String xAxisTitle) {this.xAxisTitle = xAxisTitle;return this;}public CustomCharts.ChartBuilder<T> setyAsixTitle(String yAxisTitle) {this.yAxisTitle = yAxisTitle;return this;}}/*** builder to build single series chart*/public static class ChartSingles extends CustomCharts.ChartBuilder<CustomChartSingleSeriesRenderData> {private SeriesRenderData series;/*** 宽度*/private Integer width = 10;/*** 高度*/private Integer height = 6;private ChartSingles(String chartTitle, String[] categories, ChartTypes chartTypes) {super(chartTitle, categories, chartTypes);}public CustomCharts.ChartSingles series(String name, Number[] value) {checkLengh(value.length);series = new SeriesRenderData(name, value);return this;}public CustomCharts.ChartSingles setWidthAndHeight(Integer width, Integer height) {this.width = width;this.height = height;return this;}@Overridepublic CustomChartSingleSeriesRenderData create() {CustomChartSingleSeriesRenderData data = new CustomChartSingleSeriesRenderData();data.setChartTitle(chartTitle);data.setxAxisTitle(xAxisTitle);data.setyAxisTitle(yAxisTitle);data.setCategories(categories);data.setSeriesData(series);data.setChartTypes(chartTypes);data.setWidth(width);data.setHeight(height);return data;}}
}

CustomChartSingleSeriesRenderData 数据对象

import com.deepoove.poi.data.ChartSingleSeriesRenderData;
import lombok.Data;
import org.apache.poi.xddf.usermodel.chart.ChartTypes;@Data
public class CustomChartSingleSeriesRenderData extends ChartSingleSeriesRenderData {private ChartTypes chartTypes;/*** 宽度*/private Integer width;/*** 高度*/private Integer height;
}

CustomChartRenderPolicy 插件类

import cn.hutool.core.util.StrUtil;
import com.deepoove.poi.data.SeriesRenderData;
import com.deepoove.poi.policy.AbstractRenderPolicy;
import com.deepoove.poi.render.RenderContext;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Units;
import org.apache.poi.xddf.usermodel.PresetColor;
import org.apache.poi.xddf.usermodel.XDDFColor;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
import org.apache.poi.xddf.usermodel.XDDFSolidFillProperties;
import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
import org.apache.poi.xddf.usermodel.chart.AxisPosition;
import org.apache.poi.xddf.usermodel.chart.BarDirection;
import org.apache.poi.xddf.usermodel.chart.ChartTypes;
import org.apache.poi.xddf.usermodel.chart.LegendPosition;
import org.apache.poi.xddf.usermodel.chart.MarkerStyle;
import org.apache.poi.xddf.usermodel.chart.RadarStyle;
import org.apache.poi.xddf.usermodel.chart.XDDFBarChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
import org.apache.poi.xddf.usermodel.chart.XDDFCategoryDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFChartAxis;
import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
import org.apache.poi.xddf.usermodel.chart.XDDFLineChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
import org.apache.poi.xddf.usermodel.chart.XDDFPieChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFRadarChartData;
import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
import org.apache.poi.xwpf.usermodel.XWPFChart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;import java.util.ArrayList;
import java.util.List;
import java.util.Objects;public class CustomChartRenderPolicy extends AbstractRenderPolicy<CustomChartSingleSeriesRenderData> {private Boolean titleOverlayCode;public CustomChartRenderPolicy() {this(false);}public CustomChartRenderPolicy(Boolean titleOverlayCode) {this.titleOverlayCode = titleOverlayCode;}@Overrideprotected void afterRender(RenderContext<CustomChartSingleSeriesRenderData> context) {//清空标签 clearParagraph 为true 存在表外的图表渲染不了clearPlaceholder(context, false);}@Overridepublic void doRender(RenderContext<CustomChartSingleSeriesRenderData> context) throws Exception {XWPFRun run = context.getRun();XWPFDocument xwpfDocument = (XWPFDocument)context.getXWPFDocument();CustomChartSingleSeriesRenderData singleSeriesRenderData = context.getData();if (Objects.isNull(singleSeriesRenderData)) {return;}Integer height = singleSeriesRenderData.getHeight();Integer width = singleSeriesRenderData.getWidth();//在标签位置创建chart图表对象XWPFChart chart = xwpfDocument.createChart(run, width * Units.EMU_PER_CENTIMETER, height * Units.EMU_PER_CENTIMETER);SeriesRenderData seriesData = singleSeriesRenderData.getSeriesData();//图例是否覆盖标题chart.setTitleOverlay(this.titleOverlayCode);String[] xAxisData = singleSeriesRenderData.getCategories();Number[] yAxisData = seriesData.getValues();ChartTypes chartTypes = singleSeriesRenderData.getChartTypes();//创建图表对象execChartData(chart, chartTypes, singleSeriesRenderData, xAxisData, yAxisData);//图表相关设置//图表标题if (StrUtil.isNotEmpty(singleSeriesRenderData.getChartTitle())) {chart.setTitleText(singleSeriesRenderData.getChartTitle());} else {chart.removeTitle();chart.deleteLegend();}}private static void solidFillSeries(XDDFChartData.Series series, PresetColor color) {XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(color));XDDFShapeProperties properties = series.getShapeProperties();if (properties == null) {properties = new XDDFShapeProperties();}properties.setFillProperties(fill);series.setShapeProperties(properties);}private void execChartData(XWPFChart chart, ChartTypes chartType, CustomChartSingleSeriesRenderData singleSeriesRenderData, String[] xAxisData, Number[] yAxisData) {XDDFChartData xddfChartData = null;switch (chartType) {case AREA:break;case AREA3D:break;case BAR:xddfChartData = performBarRendering(chart, chartType, singleSeriesRenderData, xAxisData, yAxisData);break;case BAR3D:break;case DOUGHNUT:break;case LINE:xddfChartData = performLineRendering(chart, chartType, singleSeriesRenderData, xAxisData, yAxisData);break;case LINE3D:break;case PIE:xddfChartData = performPieRendering(chart, chartType, singleSeriesRenderData, xAxisData, yAxisData);break;case PIE3D:break;case RADAR:performRadarRendering(chart, chartType, singleSeriesRenderData, xAxisData, yAxisData);break;case SCATTER:break;case SURFACE:break;case SURFACE3D:break;default:break;}//在标签位置绘制折线图if (Objects.nonNull(xddfChartData)) {chart.plot(xddfChartData);}}/*** PIE** @param chart* @param chartType* @param xAxisData* @param yAxisData* @return*/private XDDFChartData performPieRendering(XWPFChart chart, ChartTypes chartType, CustomChartSingleSeriesRenderData singleSeriesRenderData, String[] xAxisData, Number[] yAxisData) {// 图例位置XDDFChartLegend legend = chart.getOrAddLegend();legend.setPosition(LegendPosition.TOP_RIGHT);//设置X轴数据XDDFCategoryDataSource xAxisSource = XDDFDataSourcesFactory.fromArray(xAxisData);//设置Y轴数据XDDFNumericalDataSource<Number> yAxisSource = XDDFDataSourcesFactory.fromArray(yAxisData);//创建对象// 将数据源绑定到饼图上XDDFChartData xddfPieChartData = chart.createData(ChartTypes.PIE, null, null);XDDFPieChartData.Series series = (XDDFPieChartData.Series)xddfPieChartData.addSeries(xAxisSource, yAxisSource);series.setTitle(null,null);// 为了在饼图上显示百分比等信息,需要调用下面的方法series.setShowLeaderLines(true);if (StrUtil.isEmpty(singleSeriesRenderData.getChartTitle())) {// 隐藏图例标识、系列名称、分类名称和数值CTPieSer ctPieSer = series.getCTPieSer();showCateName(ctPieSer, false);showVal(ctPieSer, false);showLegendKey(ctPieSer, false);showSerName(ctPieSer, false);}return xddfPieChartData;}public void showCateName(CTPieSer series, boolean val) {if (series.getDLbls().isSetShowCatName()) {series.getDLbls().getShowCatName().setVal(val);} else {series.getDLbls().addNewShowCatName().setVal(val);}}public void showVal(CTPieSer series, boolean val) {if (series.getDLbls().isSetShowVal()) {series.getDLbls().getShowVal().setVal(val);} else {series.getDLbls().addNewShowVal().setVal(val);}}public void showSerName(CTPieSer series, boolean val) {if (series.getDLbls().isSetShowSerName()) {series.getDLbls().getShowSerName().setVal(val);} else {series.getDLbls().addNewShowSerName().setVal(val);}}public void showLegendKey(CTPieSer series, boolean val) {if (series.getDLbls().isSetShowLegendKey()) {series.getDLbls().getShowLegendKey().setVal(val);} else {series.getDLbls().addNewShowLegendKey().setVal(val);}}private XDDFChartData performBarRendering(XWPFChart chart, ChartTypes chartType, CustomChartSingleSeriesRenderData singleSeriesRenderData, String[] xAxisData, Number[] yAxisData) {// 定义类别轴和数值轴XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);//设置X轴数据XDDFCategoryDataSource catSource = XDDFDataSourcesFactory.fromArray(xAxisData);//设置Y轴数据XDDFNumericalDataSource<Number> valSource = XDDFDataSourcesFactory.fromArray(yAxisData);// 创建柱状图数据系列XDDFBarChartData barChartData = (XDDFBarChartData) chart.createData(chartType, bottomAxis, leftAxis);XDDFBarChartData.Series series1 = (XDDFBarChartData.Series) barChartData.addSeries(catSource, valSource);series1.setTitle("示例系列", null); // 设置系列标题// 设置柱状图样式barChartData.setBarDirection(BarDirection.COL);return barChartData;}private XDDFChartData performRadarRendering(XWPFChart chart, ChartTypes chartType, CustomChartSingleSeriesRenderData singleSeriesRenderData, String[] xAxisData, Number[] yAxisData) {List<Number[]> list = new ArrayList<>();list.add(yAxisData);setRadarData(chart, new String[]{"系列一"}, xAxisData, list);return null;}private void setRadarData(XWPFChart chart, String[] series, String[] categories,List<Number[]> list) {XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);XDDFRadarChartData radar = (XDDFRadarChartData) chart.createData(org.apache.poi.xddf.usermodel.chart.ChartTypes.RADAR, bottomAxis, leftAxis);final int numOfPoints = categories.length;final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));final XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);for (int i = 0; i < list.size(); i++) {final String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, i + 1, i + 1));final XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(list.get(i),valuesDataRange, i);XDDFChartData.Series s = radar.addSeries(categoriesData, valuesData);s.setTitle(series[i], chart.setSheetTitle(series[i], i));}radar.setStyle(RadarStyle.STANDARD);chart.plot(radar);if (list.size() > 1) {XDDFChartLegend legend = chart.getOrAddLegend();legend.setPosition(LegendPosition.BOTTOM);legend.setOverlay(false);}}/*** LINE 渲染*/private XDDFChartData performLineRendering(XWPFChart chart, ChartTypes chartType, CustomChartSingleSeriesRenderData singleSeriesRenderData, String[] xAxisData, Number[] yAxisData) {//图例设置XDDFChartLegend legend = chart.getOrAddLegend();//图例位置:上下左右legend.setPosition(LegendPosition.TOP);//X轴(分类轴)相关设置//创建X轴,并且指定位置XDDFCategoryAxis xAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);String xAxisTitle = singleSeriesRenderData.getxAxisTitle();//x轴标题if (StrUtil.isNotEmpty(xAxisTitle)) {xAxis.setTitle(xAxisTitle);}//Y轴(值轴)相关设置XDDFValueAxis yAxis = chart.createValueAxis(AxisPosition.LEFT); // 创建Y轴,指定位置if (StrUtil.isNotEmpty(singleSeriesRenderData.getyAxisTitle())) {yAxis.setTitle(singleSeriesRenderData.getyAxisTitle()); // Y轴标题}//创建折线图对象XDDFLineChartData customChartData = (XDDFLineChartData) chart.createData(chartType, xAxis, yAxis);//设置X轴数据XDDFCategoryDataSource xAxisSource = XDDFDataSourcesFactory.fromArray(xAxisData);//设置Y轴数据XDDFNumericalDataSource<Number> yAxisSource = XDDFDataSourcesFactory.fromArray(yAxisData);//加载折线图数据集XDDFLineChartData.Series lineSeries = (XDDFLineChartData.Series) customChartData.addSeries(xAxisSource, yAxisSource);//线条样式:true平滑曲线,false折线lineSeries.setSmooth(false);// 标记点样式lineSeries.setMarkerStyle(MarkerStyle.CIRCLE);//lineSeries.setMarkerSize((short) 5);return customChartData;}
}

相关文章:

word poi-tl 图表功能增强,插入图表折线图、柱状图、饼状图

目录 问题解决问题poi-tl介绍 功能实现引入依赖功能介绍 功能实例饼图模版代码效果图 雷达图&#xff08;模版同饼图&#xff09;代码效果图 柱状图&#xff08;模版同饼图&#xff09;代码效果图 附加CustomCharts 工具类CustomChartSingleSeriesRenderData 数据对象CustomCha…...

SpringBoot 项目如何集成 JWT

SpringBoot 项目如何集成 JWT JWT JSON Web Token (JWT) 是一个开放标准(RFC 7519)&#xff0c;它定义了一种紧凑的、自包含的方式&#xff0c;用于作为 JSON 对象在各方之间安全地传输信息。 在 Oauth2 中&#xff0c;其实就是返回访问令牌 &#xff08;access_token&#…...

如何查看电脑刷新率

Windows 系统 通过显示设置查看&#xff1a; 右键点击桌面空白处&#xff0c;选择 “显示设置”。在打开的窗口中&#xff0c;找到 “高级显示设置”。点击 “显示适配器属性”。在弹出的窗口中&#xff0c;选择 “监视器” 选项卡&#xff0c;即可看到当前的屏幕刷新率。使用 …...

MVC基础——市场管理系统(一)

文章目录 项目地址一、创建项目结构1.1 创建程序以及Controller1.2 创建View1.3 创建Models层,并且在Edit页面显示1.4 创建Layou模板页面1.5 创建静态文件css中间件二、Categories的CRUD2.1 使用静态仓库存储数据2.2 将Categorie的列表显示在页面中(List)2.3 创建_ViewImport.…...

面向对象中多态的含义

多态性的定义 多态&#xff08;Polymorphism&#xff09;是面向对象编程中的一个重要概念。它是指同一个函数名或操作符在不同的对象或情境下具有不同的行为。简单来说&#xff0c;就是 “多种形态”。例如&#xff0c;在一个图形处理程序中&#xff0c;有 “计算面积” 这个操…...

L2G3000-LMDeploy 量化部署实践

文章目录 LMDeploy 量化部署实践闯关任务环境配置W4A16 量化 KV cacheKV cache 量化Function call LMDeploy 量化部署实践闯关任务 环境配置 conda create -n lmdeploy python3.10 -y conda activate lmdeploy conda install pytorch2.1.2 torchvision0.16.2 torchaudio2.1.…...

ubuntu下的chattts 学习5:Example: self introduction

代码 import ChatTTS import torch import torchaudiochat ChatTTS.Chat() chat.load(compileFalse) # Set to True for better performance ################################### inputs_en """ chat T T S is a text to speech model designed for dialogu…...

IDEA的service窗口中启动类是灰色且容易消失

大家在学习Spring Cloud的过程中,随着项目的深入,会分出很多个微服务,当我们的服务数量大于等于三个的时候,IDEA会给我们的服务整理起来,类似于这样 但是当我们的微服务数量达到5个以上的时候,再启动服务的时候,服务的启动类就会变成灰色,而且还容易丢失 解决方法 我们按住…...

vue中pdf.js的使用,包括pdf显示,跳转指定页面,高亮关键词

目录 一、下载pdf.js 二、引入到本地的项目中 三、实现预览pdf 四、跳转到指定页面 五、利用pdf里面的find查找关键词 六、修改页面大小为实际大小 一、下载pdf.js https://github.com/mozilla/pdf.js 里面有很多的版本&#xff0c; 高版本的可能浏览器不兼容或者还要考…...

Cherno C++学习笔记 P32 字符串

这篇文章我们来讲字符串。字符串可以说是最重要的变量类型了&#xff0c;因为对字符串的读写极大地影响到我们的程序和用户之间的交互。甚至很多很庞大的程序就只是在处理字符串。 对于字符串&#xff0c;我们同时需要有关于数组和指针的关系&#xff0c;字符串的实现与数组是…...

【C++初阶】第7课—标准模版库STL(string_1)

文章目录 1. 什么是STL2. STL六大组件3. 标准库中string类3.1 auto关键字3.2 范围for3.3 string类的类型3.4 string类的常用接口(string类对象的常见构造)3.5 string的析构和赋值运算符重载3.6 string类对象的容量操作 1. 什么是STL STL(standard template library—标准模板库…...

GESP202306 一级【时间规划】题解(AC)

》》》点我查看「视频」详解》》》 AC_Code #include <bits/stdc.h> using namespace std;int main() {int h1, m1, h2, m2;cin >> h1 >> m1;cin >> h2 >> m2;h1 h1 * 60 m1;h2 h2 * 60 m2;cout << h2 - h1;return 0; }》》》点我查…...

React基础知识四 Hooks

什么是hooks&#xff1f; (coderwhy) hooks是react 16.8&#xff08;2019年&#xff09;出的新特性。 react有两种形式来创建组件——类式和函数式。在hooks之前类式组件就是react最主流的编程方式。 这个时候&#xff0c;函数式组件是非常鸡肋的&#xff0c;几乎没什么用。因…...

Linux服务器通用安全加固指南

1、保护引导过程&#xff08;以Grub引导为例&#xff09; 在 /etc/inittab 中添加 sp:S:respawn:/sbin/sulogin&#xff0c;以确保当切换到单用户模式时 运行级的配置要求输入 root 密码&#xff1a; cp /etc/inittab / etc/initab .bak vim /etc/inittab 退出&#xff1a;es…...

vsphere vcenter web 界面的介绍

这是主页的页面...

分类算法中的样本不平衡问题及其解决方案

一、样本不平衡问题概述 在机器学习的分类任务中&#xff0c;样本不平衡是指不同类别训练样本数量存在显著差异的现象。这一差异会给模型训练和性能评估带来挑战&#xff0c;尤其在处理少数类样本时&#xff0c;模型可能难以有效学习其特征。 以二分类为例&#xff0c;理想情况…...

[LitCTF 2023]破损的图片(初级)

[LitCTF 2023]破损的图片(初级) 我们下载附件得到一个没有后缀的文件&#xff0c;拖去010看一看&#xff0c;发现本来应该是文件头的那部分不大对劲&#xff0c;结合后面四个点以及IHDR&#xff0c;大致也应该知道是啥了 修改第一行为png 89 50 4E 47 0D 0A 1A 0A 00 00 00 …...

最新道客巴巴怎么免费下载文档方法

一、利用浏览器插件 插件自动识别下载&#xff1a;对于经常需要下载道客巴巴文档的人来说&#xff0c;安装浏览器插件是不错的选择。如Chrome浏览器上的一些插件&#xff08;如PDF在线转换器等&#xff09;&#xff0c;安装后&#xff0c;在浏览器中打开道客巴巴文档&#xff…...

Bert的Transformer原理

多义词如何应对&#xff1a; 答&#xff1a;通过Self attention&#xff0c;不同的上下文&#xff0c;对同一个"苹果"&#xff0c;得到截然不同的embedding激活值&#xff1b; Multi-head的作用&#xff1a; 有些类似CNN里用的多个卷积核得到多个Channel的特征图&…...

多人聊天室 NIO模型实现

NIO编程模型 Selector监听客户端不同的zhuangtai不同客户端触发不同的状态后&#xff0c;交由相应的handles处理Selector和对应的处理handles都是在同一线程上实现的 I/O多路复用 在Java中&#xff0c;I/O多路复用是一种技术&#xff0c;它允许单个线程处理多个输入/输出&…...

vue.js学习(day 20)

综合案例&#xff1a;购物车 数据渲染 构建cart购物车模块 准备后端接口服务环境 请求数据存入vuex cart.js // 新建购物车模块 import axios from axios export default {namespaced: true,state () {return {// 购物车数据 [{},{}]list: []}},mutations: {updateList (…...

蓝桥杯二分题

P1083 [NOIP2012 提高组] 借教室 题目描述 在大学期间&#xff0c;经常需要租借教室。大到院系举办活动&#xff0c;小到学习小组自习讨论&#xff0c;都需要向学校申请借教室。教室的大小功能不同&#xff0c;借教室人的身份不同&#xff0c;借教室的手续也不一样。 面对海量租…...

通过 CC-Link IEFB 转 Modbus RTU 网关达成三菱 FX5U PLC 与 RS485 温湿度传感器通信的配置实例展示

一. 案例背景 在某一化工厂现场&#xff0c;现场的设备是三菱FX5UPLC为了避免因为工作环境存在潮湿度较高性、较高温度等对员工造成不健康或危险的现象&#xff0c;现决定在现场装数多台温湿度传感器。通过捷米特JM-CCLKIE-RTU网关将三菱PLC及温湿度传感器连接起来并连接上位机…...

视频质量评价算法 DOVER 使用教程

DOVER 介绍 DOVER是为ICCV2023会议论文“Exploring Video Quality Assessment on User Generated Contents from Aesthetic and Technical Perspectives”提供的官方代码、演示和权重的项目。DOVER(Disentangled Objective Video Quality Evaluator)是一个用于评估用户生成内…...

视频编辑技术:一键生成混剪视频的AI技术应用

随着视频内容的爆炸式增长&#xff0c;视频编辑技术也在不断进步。本文将探讨如何利用AI技术&#xff0c;实现一键生成混剪视频&#xff0c;并自动添加配音和字幕&#xff0c;以提高视频编辑的效率和质量。 AI技术在视频编辑中的应用 AI技术在视频编辑领域的应用越来越广泛&am…...

精确的单向延迟测量:使用普通硬件和软件

论文标题&#xff1a;Precise One-way Delay Measurement with Common Hardware and Software&#xff08;精确的单向延迟测量&#xff1a;使用普通硬件和软件&#xff09; 作者信息&#xff1a;Maciej Muehleisen 和 Mazen Abdel Latif&#xff0c;来自Ericsson Research Eri…...

【博士每天一篇文献-COIL算法】Co-transport for class-incremental learning

1 介绍 年份&#xff1a;2021 会议&#xff1a;2021ACM Zhou D W, Ye H J, Zhan D C. Co-transport for class-incremental learning[C]//Proceedings of the 29th ACM International Conference on Multimedia. 2021: 1645-1654. 本文提出的算法是CO-transport for clas…...

AI与BI的火花:大语言模型如何重塑商业智能的未来

大家好&#xff0c;我是独孤风。 在当今这个数据驱动的时代&#xff0c;企业对于信息的需求如同对于氧气的需求一般至关重要。商业智能&#xff08;BI&#xff09;作为企业获取、分析和呈现数据的关键工具&#xff0c;正在经历一场深刻的变革&#xff0c;而这一变革的催化剂正是…...

C++设计模式(建造者、中介者、备忘录)

一、建造者模式 将一个复杂对象的构建与它的表示分离&#xff0c;使得同样的构建过程可以创建不同的表示。 示例&#xff1a; //房子&#xff08;产品类&#xff09; class House { private:int rooms;int windows;string decoration; public:void setRooms(int r) {rooms …...

【数据结构】遍历二叉树

遍历二叉树的算法描述&#xff08;递归定义&#xff09; 先序遍历 若二叉树为空&#xff0c;则空操作&#xff1b; 否则 &#xff08;1&#xff09;访问根节点 &#xff08;2&#xff09;先序遍历左子树 &#xff08;3&#xff09;先序遍历右子树 中序遍历 若二叉树为空…...

鸿蒙获取 APP 信息及手机信息

前言&#xff1a;获取 APP 版本信息可以通过 bundleManager.getBundleInfoForSelfSync(bundleFlags) 去获取&#xff0c;获取手机信息可以通过 kit.BasicServicesKit 库去获取&#xff0c;以下是封装好的工具类。 import bundleManager from ohos.bundle.bundleManager; impo…...

OpenWRT下深入了解IPv6——SLAAC

一、SLAAC&#xff08;无状态地址自动配置&#xff09; 1.基本原理 SLAAC 是 IPv6 中的一种地址自动配置机制&#xff0c;它允许设备根据网络中的路由器通告信息和自身的 MAC 地址自动生成 IPv6 地址。在 IPv6 网络中&#xff0c;MAC 地址长度为 48 位&#xff0c;而 IPv6 地…...

UE5水文章 UI按钮样式快捷复制黏贴

shift右键拷贝 shift右键黏贴...

迭代器模式的理解和实践

引言 在软件开发中&#xff0c;我们经常需要遍历容器对象&#xff08;如数组、列表、集合等&#xff09;中的元素。如果每个容器对象都实现自己的遍历算法&#xff0c;那么代码将会变得冗余且难以维护。为了解决这个问题&#xff0c;迭代器模式应运而生。迭代器模式是一种行为型…...

Python __func 与 _func 的区别引起的思考

文章目录 __function_function深入名称修饰机制名称修饰的目的实现原理 属性访问控制的高级模式基本模式扩展复杂的转换和验证逻辑带有日志和审计的访问控制 如果突然让我说一说 Python中的__function和_function有哪些不同的约定和用途&#xff0c;我好像一下子没法说出很多东…...

python学opencv|读取视频(二)制作gif

【1】引言 前述已经完成了图像和视频的读取学习&#xff0c;本次课学习制作gif格式动图。 【2】教程 实际上想制作gif格式动图是一个顺理成章的操作&#xff0c;完成了图像和视频的处理&#xff0c;那就自然而然会对gif的处理也产生兴趣。 不过在opencv官网、matplotlib官网…...

Redmi AX3000 (RA81) 路由器恢复原厂固件

最近给Redmi AX3000 (RA81) 刷了OpenWrt固件&#xff0c;但是存在各种小问题&#xff0c;因此决定刷回原厂固件。刷机之前保证能够访问路由器ssh&#xff0c;否则请百度救砖教程。 准备工具 Redmi AX3000 (RA81) 原厂分区文件 [github下载地址 / csdn下载地址]小米路由器修复…...

【调试工具】USB 转 UART 适配器(USB 转 TTL)

「USB 转 TTL 转换器」是错误的叫法&#xff0c;正确的叫法应该为 「USB 转 UART 适配器」。 Device connection 注意端口的交叉连接&#xff0c;Device1_TX<---->Device2_RX USB-to-UART adapter GND 记得接地。 使用&#xff1a; 当 TX,RX 需要电平为 0-3.3V 时&am…...

【YOLO部署Android安卓手机APP】YOLOv11部署到安卓实时目标检测识别——以火焰烟雾目标检测识别举例(可自定义更换其他目标)

前言:本项目基于YOLOv11部署到手机APP实现对火焰烟雾的检测识别,当然,以此你可以按照本项目开发步骤扩展更换为其他目标进行检测,例如更换为车牌、手势、人脸面部活动、人脸表情、火焰烟雾、行人、口罩、行为、水果、植物、农作物等等部署手机APP进行检测。本文为详细设计/…...

Python 中的 __slots__ 属性有什么作用?

__slots__ 是Python类中的一种特殊属性&#xff0c;它允许你显式地声明一个类的实例可以拥有的属性。 这不仅有助于节省内存&#xff0c;还能提高属性访问的速度&#xff0c;并且防止动态添加不属于设计的属性。 在大型项目或者对性能敏感的应用程序中&#xff0c;正确使用 _…...

【H2O2|全栈】Node.js与MySQL连接

目录 前言 开篇语 准备工作 初始配置 创建连接池 操作数据库 封装方法 结束语 前言 开篇语 本节讲解如何使用Node.js实现与MySQL数据库的连接&#xff0c;并将该过程进行函数封装。 与基础部分的语法相比&#xff0c;ES6的语法进行了一些更加严谨的约束和优化&#…...

【大数据技术基础】 课程 第3章 Hadoop的安装和使用 大数据基础编程、实验和案例教程(第2版)

第3章 Hadoop的安装和使用 3.1 Hadoop简介 Hadoop是Apache软件基金会旗下的一个开源分布式计算平台&#xff0c;为用户提供了系统底层细节透明的分布式基础架构。Hadoop是基于Java语言开发的&#xff0c;具有很好的跨平台特性&#xff0c;并且可以部署在廉价的计算机集群中。H…...

DDR4与DDR3服务器内存的关键区别有哪些?

内存作为服务器性能的关键组件之一&#xff0c;已经经历了从DDR3到DDR4的过渡。DDR4内存相较于DDR3在多个方面有所提升&#xff0c;包括速度、带宽、功耗以及数据传输效率等。然而&#xff0c;尽管DDR4内存在性能上占有优势&#xff0c;DDR3内存依然在一些特定场景中得到了广泛…...

OceanBase 的探索与实践

作者&#xff1a;来自 vivo 互联网数据库团队- Xu Shaohui 本文总结了目前我们遇到的痛点问题并通过 OceanBase 的技术方案解决了这些痛点问题&#xff0c;完整的描述了 OceanBase 的实施落地&#xff0c;通过迁移到 OceanBase 实践案例中遇到的问题与解决方案让大家能更好的了…...

2024年安全员-A证证模拟考试题库及安全员-A证理论考试试题

2024年安全员-A证模拟考试题库及理论考试试题&#xff08;一&#xff09; 单选题 根据《建筑施工企业主要负责人、项目负责人和专职安全生产管理人员安全生产管理规定》&#xff0c;项目负责人每月带班生产时间不得少于本月施工时间的&#xff08; &#xff09;。 A. 60% B. …...

安装Docker并使用WSL

引言 Windows Subsystem for Linux (WSL) 是一个在Windows上运行Linux二进制可执行文件&#xff08;ELF格式&#xff09;的兼容层。它允许开发者直接在Windows上运行Linux环境&#xff0c;而无需使用虚拟机。Docker是一个开源的应用容器引擎&#xff0c;它允许开发者打包应用以…...

【TCP 网络通信(发送端 + 接收端)实例 —— Python】

TCP 网络通信&#xff08;发送端 接收端&#xff09;实例 —— Python 1. 引言2. 创建 TCP 服务器&#xff08;接收端&#xff09;2.1 代码示例&#xff1a;TCP 服务器2.2 代码解释&#xff1a; 3. 创建 TCP 客户端&#xff08;发送端&#xff09;3.1 代码示例&#xff1a;TCP…...

PostgreSQL和Oracle的sql差异

PostgreSQL和Oracle的sql差异 1.rownum &#xff08;1&#xff09;Oracle分页查询使用rownum&#xff0c;PostgreSQL使用limit offset ORACLEPOSTGRESQLselect * from (select rownum r,e.* from emp e where rownum <5) t where r>0;select * from emp limit 5 offset…...

阻塞队列详解

阻塞队列介绍 队列 是限定在一端进行插入&#xff0c;另一端进行删除的特殊线性表。先进先出(FIFO)线性表。允许出队的一端称为队头&#xff0c;允许入队的一端称为队尾。 数据结构演示网站&#xff1a; https://www.cs.usfca.edu/~galles/visualization/Algorithms.html Q…...

kali安装谷歌输入法

临时隐匿你IP地址 ifconfig 查询kali现在所用ip ifconfig eth0 所需要修改的ip/掩码24 修改临时ip格式命令 安装中文输入法命令 临时隐匿你IP地址 ifconfig 查询kali现在所用ip ifconfig eth0 所需要修改的ip/掩码24 修改临时ip格式命令安装中文输入法命令 apt-get in…...