Java导入、导出excel保姆级教程(附封装好的工具类)

news2024/9/20 0:11:29

前言

我们在日常开发中,一定遇到过要将数据导出为Excel的需求,那么怎么做呢?在做之前,我们需要思考下Excel的组成。Excel是由四个元素组成的分别是:WorkBook(工作簿)、Sheet(工作表)、Row(行)、Cell(单元格),其中包含关系是从左至右,一个WorkBook可以包含多个Sheet,一个Sheet又是由多个Row组成,一个Row是由多个Cell组成。知道这些后那么我们就使用java来将数据以Excel的方式导出。让我们一起来学习吧!

一、引入Apache POI依赖

使用Java实现将数据以Excel的方式导出,需要依赖第三方的库。我们需要再pom.xml中引入下面的依赖:

 <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>

二、用法&步骤

2.1 创建Excel的元素

1)创建WokrBook

Workbook workbook = new XSSFWorkbook();

2)创建Sheet

 Sheet sheet = workbook.createSheet();

 设置sheet的名称

 Sheet sheet = workbook.createSheet("sheet名称");

3)创建行Row

      
      Row row = sheet.createRow(0);

    

4)创建单元格Cell

      
      Cell cell = row.createCell(0, CellType.STRING);

    

可以指定单元格的类型,支持的类型有下面7种:

      
      _NONE(-1),
NUMERIC(0),
STRING(1),
//公式
FORMULA(2),
BLANK(3),
//布尔
BOOLEAN(4),
ERROR(5);

    

5) 填充数据

      
       cell.setCellValue("苹果");

    

2.3 样式和字体

如果我们需要导出的Excel美观一些,如设置字体的样式加粗、颜色、大小等等,就需要创建样式和字体。

创建样式:

      
      CellStyle cellStyle = workbook.createCellStyle();

    

1)左右垂直居中

      
      //左右居中
excelTitleStyle.setAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
excelTitleStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    

2)字体加粗、颜色

创建加粗样式并设置到CellStyle 中:

      
      Font font = workbook.createFont();
//字体颜色为红色
font.setColor(IndexedColors.RED.getIndex());
//字体加粗
font.setBold(true);
cellStyle.setFont(font);

    

指定Cell单元格使用该样式:

      
      cell.setCellStyle(style);

    

3)调整列宽和高

      
      Sheet sheet = workbook.createSheet();
//自动调整列的宽度来适应内容
sheet.autoSizeColumn(int column); 
// 设置列的宽度
sheet.setColumnWidth(2, 20 * 256); 

    

autoSizeColumn()传递的参数就是要设置的列索引。setColumnWidth()第一个参数是要设置的列索引,第二参数是具体的宽度值,宽度 = 字符个数 * 256(例如20个字符的宽度就是20 * 256

4)倾斜、下划线

      
      Font font = workbook.createFont();
font.setItalic(boolean italic); 设置倾斜
font.setUnderline(byte underline); 设置下划线

    

2.4 进阶用法

1)合并单元格

      
      Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet(fileName);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

    

CellRangeAddress()方法四个参数分别是fristRow:起始行、lastRow:结束行、fristCol:起始列、lastCol:结束列。

如果你想合并从第一行到第二行从一列到第十列的单元格(一共合并20格),那么就是CellRangeAddress(0,1,0,10)

2)字段必填

      
      //创建数据验证
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
//创建要添加校验的单元格对象
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 10);
//创建必填校验规则
DataValidationConstraint constraint = validationHelper.createCustomConstraint("NOT(ISBLANK(A1))");
//设置校验
DataValidation validation = dvHelper.createValidation(constraint, addressList);
//校验不通过 提示
validation.setShowErrorBox(true);
sheet.addValidationData(validation);

    

CellRangeAddressList()方法传递四个参数,分别是:fristRow:起始行、lastRow:结束行、fristCol:起始列、lastCol:结束列。CellRangeAddressList(0, 0, 0, 10)表示的就是给第一行从第一列开始到第十列一共十个单元格添加数据校验。

3)添加公式

SUM:求和函数

      
      //创建SUM公式
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
Cell sumCell = row.createCell(0);
sumCell.setCellFormula("SUM(A1:A10)");
//计算SUM公式结果
Cell sumResultCell = row.createCell(1);
sumResultCell.setCellValue(evaluator.evaluate(sumCell).getNumberValue());

    

AVERAGE:平均数函数

      
      //创建AVERAGE公式
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
Cell averageCell = row.createCell(0);
averageCell.setCellFormula("AVERAGE(A1:A10)");

//计算AVERAGE公式结果
Cell averageResultCell = row.createCell(1);
averageResultCell.setCellValue(evaluator.evaluate(averageCell).getNumberValue());

    

COUNT:计数函数

      
      //创建COUNT公式
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
Cell countCell = row.createCell(0);
countCell.setCellFormula("COUNT(A1:A10)");

//计算COUNT公式结果
Cell countResultCell = row.createCell(1);
countResultCell.setCellValue(evaluator.evaluate(countCell).getNumberValue());

    

IF:条件函数

      
      //创建IF公式
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
Cell ifCell = row.createCell(0);
ifCell.setCellFormula("IF(A1>B1,\"Yes\",\"No\")");

//计算IF公式结果
Cell ifResultCell = row.createCell(1);
ifResultCell.setCellValue(evaluator.evaluate(ifCell).getStringValue());

    

CONCATENATE:连接函数

      
      //创建CONCATENATE公式
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
Cell concatenateCell = row.createCell(0);
concatenateCell.setCellFormula("CONCATENATE(A1,\" \",B1)");

//计算CONCATENATE公式结果
Cell concatenateResultCell = row.createCell(1);
concatenateResultCell.setCellValue(evaluator.evaluate(concatenateCell).getStringValue());

    

4)下拉选择

      
      //下拉值
private List<String> grade = Arrays.asList("高", "中", "低");
(此处省略n行代码)
Sheet sheet = workbook.createSheet("sheet");
DataValidation dataValidation = this.addPullDownConstraint(i, sheet, grade );
sheet.addValidationData(dataValidation);

    

5)设置单元格的数据类型

数字格式

      
      // 设置单元格样式 - 数字格式
CellStyle numberCellStyle = workbook.createCellStyle();
numberCellStyle.setDataFormat(workbook.createDataFormat().getFormat("#,##0.00"));
//指定单元格
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellStyle(numberCellStyle);

    

日期格式

      
      // 设置单元格样式 - 日期格式
CellStyle dateCellStyle = workbook.createCellStyle();
dateCellStyle.setDataFormat(workbook.createDataFormat().getFormat("yyyy-MM-dd"));
//指定单元格
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellStyle(dateCellStyle);

    

三、导出完整示例

下面的示例使用SpringBoot项目来演示:

pom.xml依赖:

      
       <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.7.5</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>2.7.5</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>4.1.2</version>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>2.0.21</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.12.0</version>
</dependency>

    

Controller层代码:

      
      package shijiangdiya.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shijiangdiya.utils.ExportUtils;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/sync")
public class ExportController {
}

    

1)代码

      
      @Autowired
private HttpServletResponse response;

@PostMapping("/export")
public void export() {
 //模拟json数据
    String data = "[{\n" +
            "    \"studentId\": \"20210101\",\n" +
            "    \"name\": \"Alice\",\n" +
            "    \"age\": 20,\n" +
            "    \"credit\": 80\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210102\",\n" +
            "    \"name\": \"Bob\",\n" +
            "    \"age\": 21,\n" +
            "    \"credit\": 85\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210103\",\n" +
            "    \"name\": \"Charlie\",\n" +
            "    \"age\": 22,\n" +
            "    \"credit\": 90\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210104\",\n" +
            "    \"name\": \"David\",\n" +
            "    \"age\": 20,\n" +
            "    \"credit\": 75\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210105\",\n" +
            "    \"name\": \"Emily\",\n" +
            "    \"age\": 21,\n" +
            "    \"credit\": 82\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210106\",\n" +
            "    \"name\": \"Frank\",\n" +
            "    \"age\": 22,\n" +
            "    \"credit\": 88\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210107\",\n" +
            "    \"name\": \"Grace\",\n" +
            "    \"age\": 20,\n" +
            "    \"credit\": 81\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210108\",\n" +
            "    \"name\": \"Henry\",\n" +
            "    \"age\": 21,\n" +
            "    \"credit\": 89\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210109\",\n" +
            "    \"name\": \"Isaac\",\n" +
            "    \"age\": 22,\n" +
            "    \"credit\": 92\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210110\",\n" +
            "    \"name\": \"John\",\n" +
            "    \"age\": 20,\n" +
            "    \"credit\": 78\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210111\",\n" +
            "    \"name\": \"Kelly\",\n" +
            "    \"age\": 21,\n" +
            "    \"credit\": 84\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210112\",\n" +
            "    \"name\": \"Linda\",\n" +
            "    \"age\": 22,\n" +
            "    \"credit\": 87\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210113\",\n" +
            "    \"name\": \"Mike\",\n" +
            "    \"age\": 20,\n" +
            "    \"credit\": 77\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210114\",\n" +
            "    \"name\": \"Nancy\",\n" +
            "    \"age\": 21,\n" +
            "    \"credit\": 83\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210115\",\n" +
            "    \"name\": \"Oscar\",\n" +
            "    \"age\": 22,\n" +
            "    \"credit\": 91\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210116\",\n" +
            "    \"name\": \"Paul\",\n" +
            "    \"age\": 20,\n" +
            "    \"credit\": 76\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210117\",\n" +
            "    \"name\": \"Queen\",\n" +
            "    \"age\": 21,\n" +
            "    \"credit\": 86\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210118\",\n" +
            "    \"name\": \"Rachel\",\n" +
            "    \"age\": 22,\n" +
            "    \"credit\": 94\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210119\",\n" +
            "    \"name\": \"Sarah\",\n" +
            "    \"age\": 20,\n" +
            "    \"credit\": 79\n" +
            "  },\n" +
            "  {\n" +
            "    \"studentId\": \"20210120\",\n" +
            "    \"name\": \"Tom\",\n" +
            "    \"age\": 21,\n" +
            "    \"credit\": 80\n" +
            "  }\n" +
            "]\n";
    ExportUtils.exportExcel("学生信息", data, Student.class, response);
}

    

2)工具类

      
        /**
 * 数据导出
 * @param fileName 导出excel名称
 * @param data 导出的数据
 * @param c 导出数据的实体class
 * @param response 响应
 * @throws Exception
 */
public static void exportExcel(String fileName, String data, Class<?> c, HttpServletResponse response) throws Exception {
    try {
        // 创建表头
        // 创建工作薄
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();
        // 创建表头行
        Row rowHeader = sheet.createRow(0);
        if (c == null) {
            throw new RuntimeException("Class对象不能为空!");
        }
        Field[] declaredFields = c.getDeclaredFields();
        List<String> headerList = new ArrayList<>();
        if (declaredFields.length == 0) {
            return;
        }
        for (int i = 0; i < declaredFields.length; i++) {
            Cell cell = rowHeader.createCell(i, CellType.STRING);
            String headerName = String.valueOf(declaredFields[i].getName());
            cell.setCellValue(headerName);
            headerList.add(i, headerName);
        }
        // 填充数据
        List<?> objects = JSONObject.parseArray(data, c);
        Object obj = c.newInstance();
        if (!CollectionUtils.isEmpty(objects)) {
            for (int o = 0; o < objects.size(); o++) {
                Row rowData = sheet.createRow(o + 1);
                for (int i = 0; i < headerList.size(); i++) {
                    Cell cell = rowData.createCell(i);
                    Field nameField = c.getDeclaredField(headerList.get(i));
                    nameField.setAccessible(true);
                    String value = String.valueOf(nameField.get(objects.get(o)));
                    cell.setCellValue(value);
                }
            }
        }
        response.setContentType("application/vnd.ms-excel");
        String resultFileName = URLEncoder.encode(fileName, "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + resultFileName + ";" + "filename*=utf-8''" + resultFileName);
        workbook.write(response.getOutputStream());
        workbook.close();
        response.flushBuffer();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

    

3)结果

49e92167697a79385766d0ff9329bb75.webp

四、导入完整示例

1)代码

      
      @PostMapping("/import")
public void importExcel(@RequestParam("excel") MultipartFile excel){
    Workbook workbook = null;
    try {
        workbook = WorkbookFactory.create(excel.getInputStream());
        Sheet sheet = workbook.getSheetAt(0);
        List<Student> students = new ArrayList<>();
        int i = 0;
        for (Row row : sheet) {
            Row row1 = sheet.getRow(i + 1);
            if(row1 != null){
                Student data = new Student();
                data.setStudentId(Integer.parseInt(row1.getCell(0).getStringCellValue()));
                data.setName(row1.getCell(1).getStringCellValue());
                data.setAge(Integer.parseInt(row1.getCell(2).getStringCellValue()));
                data.setCredit(Integer.parseInt(row1.getCell(3).getStringCellValue()));
                students.add(data);
            }
        }
        System.out.println(students);
        workbook.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    

2)工具类

      
       /**
     * 导入
     * @param workbook 工作簿
     * @param c 实体类
     * @return 实体类集合
     */
    public static <T> List<T> importExcel(Workbook workbook,Class<?> c){
        List<T> dataList = new ArrayList<>();
        try {
            Sheet sheet = workbook.getSheetAt(0);
            int i = 0;
            T o = null;
            for (Row row : sheet) {
                Row row1 = sheet.getRow(i + 1);
                if(row1 != null){
                    o = (T) c.newInstance();
                    Field[] declaredFields = c.getDeclaredFields();
                    for (int i1 = 0; i1 < declaredFields.length; i1++) {
                        String name = declaredFields[i1].getName();
                        Field declaredField1 = o.getClass().getDeclaredField(name);
                        declaredField1.setAccessible(true);
                        Cell cell = row1.getCell(i1);
                        String type = declaredFields[i1].getType().getName();
                        String value = String.valueOf(cell);
                        if(StringUtils.equals(type,"int") || StringUtils.equals(type,"Integer")){
                            declaredField1.set(o,Integer.parseInt(value));
                        } else if(StringUtils.equals(type,"java.lang.String") || StringUtils.equals(type,"char") || StringUtils.equals(type,"Character") ||
                                StringUtils.equals(type,"byte") || StringUtils.equals(type,"Byte")){
                            declaredField1.set(o,value);
                        } else if(StringUtils.equals(type,"boolean") || StringUtils.equals(type,"Boolean")){
                            declaredField1.set(o,Boolean.valueOf(value));
                        } else if(StringUtils.equals(type,"double") || StringUtils.equals(type,"Double")){
                            declaredField1.set(o,Double.valueOf(value));
                        } else if (StringUtils.equals(type,"long") || StringUtils.equals(type,"Long")) {
                            declaredField1.set(o,Long.valueOf(value));
                        } else if(StringUtils.equals(type,"short") || StringUtils.equals(type,"Short")){
                            declaredField1.set(o,Short.valueOf(value));
                        } else if(StringUtils.equals(type,"float") || StringUtils.equals(type,"Float")){
                            declaredField1.set(o,Float.valueOf(value));
                        }
                    }
                }
                dataList.add(o);
            }
            workbook.close();
            return dataList;
        }catch (Exception e){
            e.printStackTrace();
        }
        return dataList;
    }

    

注意:导入工具类仅限Java的八大基础数据类型和String类型。如果还有其他类型需要自己扩展。

3)结果

学生信息集合:

e6d56cd21f3dcafbb17abd48c11e95ed.webp

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2125375.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

深度学习-目标检测(四)-Faster R-CNN

目录 一.模型框架 二&#xff1a;步骤详细 1.conv layers 2.RPN 3.anchors 4.cls layer分类 5.reg layer回归 6.Proprosal 7.Rol pooling 8.Classification 三.训练 1.训练RPN网络 2.全连接层部分训练&#xff1a; 都看到这里了&#xff0c;点个赞把&#xff01;&a…

adb有线连接正常,adb connect失败

adb connect失败 1. 确认两个设备在同一个局域网 2. 确认此网络是否有adb连接的权限(有的公司网络不允许adb) 3. 确认防火墙设置 如果前面3步都确认没问题&#xff0c;Ping ip也能成功&#xff0c;那么有可能就是端口的问题: step1&#xff1a; 先用有线连接设备&#xff0…

DBeaver连接数据库报连接错误:Public Key Retrieval is not allowed

问题描述 使用DBeaver软件连接mysql数据库的时候&#xff0c;有如下提示信息&#xff1a; 解决办法 点击驱动属性->找到allowPublicKeyRetrieval这项&#xff0c;把值设置为TRUE,再点击连接测试 可以成功连接到mysql数据库&#xff0c;问题解决~

面试题 Spring bean 循环依赖解决方案以及三级缓存讲解

文章目录 Spring bean 循环依赖1.1 什么是循环依赖1.2 Spring循环依赖几种情况 什么是三级缓存到底是什么东西&#xff0c;三级缓存做了什么&#xff1f;三级缓存源码讲解 Spring bean 循环依赖 1.1 什么是循环依赖 当面试官问到你给我讲一下什么是循环依赖吧&#xff0c;该如…

简单数据库sqlite

目录 数据库 简介 1、分类&#xff1a; 大型 中型 小型 2、名词&#xff1a; 3、嵌入式数据库&#xff1a; 4、sqlite3的安装&#xff1a; LTS long term support 5.1、sqlite3的使用&#xff1a; 0、启动sqlite3 1、系统维护命令&#xff1a;> .help 5.2、标准SQL…

盘点4款高效率的PDF在线编辑工具

PDF格式的文件在分享和传输这方面确实要比七个格式的文件要方便一些&#xff0c;但正因为如此&#xff0c;导致有的时候编辑起来不是很方便。这个时候专业的PDF编辑工具就变得很重要&#xff0c;尤其是在线编辑工具&#xff0c;不用下载就可以直接使用。所以我便要跟大家分享几…

探索GPU算力在大模型和高性能计算中的无限潜能

在当今科技领域&#xff0c;大模型和高性能计算正以惊人的速度发展。大模型如语言模型、图像识别模型等&#xff0c;规模越来越大&#xff0c;精度越来越高&#xff0c;能够处理复杂的任务和生成逼真的结果。高性能计算则凭借强大的计算能力&#xff0c;推动着科学研究、工程设…

黑马点评18——多级缓存-OpenResty

文章目录 安装OpenRestyOpenResty快速入门OpenResty获取请求参数封装Http请求向Tomcat发送http请求根据商品id对tomcat集群负载均衡Redis缓存预热查询Redis缓存Nginx本地缓存 安装OpenResty 安装参考博客 OpenResty快速入门 nginx是没有业务能力的&#xff0c;我们是把请求转发…

月考成绩发布,老师该用什么工具?

九月已过半&#xff0c;我们即将迎来第一次月考。对于老师们来说&#xff0c;这不仅是对学生学习成果的一次检验&#xff0c;也是老师忙碌工作的开始。考试结束后&#xff0c;老师们需要投入大量的时间和精力来统计和发布成绩。那么&#xff0c;在这个信息化时代&#xff0c;老…

新手老师都在用的月考成绩发布方式

新学期马上一个月了&#xff0c;学生们即将迎来第一次月考。月考是孩子们学习成果的一次大考&#xff0c;也是老师们忙得团团转的时候。在日常的教学工作中&#xff0c;老师们常常被繁琐的成绩发布工作所困扰。为简化这一流程&#xff0c;易查分提供了一个高效且便捷的解决方案…

无人机复合材料

无人机复合材料是无人机制造中不可或缺的重要材料&#xff0c;它们以其独特的性能优势在无人机设计中发挥着关键作用。 一、无人机复合材料概述 无人机复合材料是由两种或两种以上不同性能、形态的材料&#xff0c;通过复合工艺组合而成的新型材料。这些材料在继承原有材料主要…

【C++二分查找】911. 在线选举

本文涉及的基础知识点 C二分查找 LeetCode911. 在线选举 给你两个整数数组 persons 和 times 。在选举中&#xff0c;第 i 张票是在时刻为 times[i] 时投给候选人 persons[i] 的。 对于发生在时刻 t 的每个查询&#xff0c;需要找出在 t 时刻在选举中领先的候选人的编号。 在…

Linux 环境下Mysql没有开放公网端口连接创建数据库

一、情况描述&#xff1a; 服务器切换迁移&#xff0c;需要重新部署服务&#xff0c;由于该服务器上不能装docker&#xff0c;只能用apt命令安装 openjdk&#xff08;乌班图系统&#xff09;故只能用最原始的方法部署服务。 已知服务器IP地址&#xff0c;且服务器上面已经安装了…

一键解读Hive数仓工具!

在数字化时代&#xff0c;数据仓库已成为企业的核心资产&#xff0c;它不仅仅是一个存储大量数据的场所&#xff0c;更是企业洞察过去、把握现在、预见未来的重要工具。随着大数据技术的发展和应用&#xff0c;数据仓库的重要性愈发凸显&#xff0c;它能够帮助企业从海量的数据…

论文阅读:3D Gaussian Splatting for Real-Time Radiance Field Rendering

论文地址&#xff1a;https://arxiv.org/abs/2308.04079 代码地址&#xff1a;graphdeco-inria/gaussian-splatting: Original reference implementation of "3D Gaussian Splatting for Real-Time Radiance Field Rendering" (github.com) 概要 提出一个实时且能够…

React18快速入门

https://www.bilibili.com/video/BV1pF411m7wV 需要先安装并配置React相关的工具和插件 下载安装Node.js&#xff0c;这里以MacOS Node.js v22.6.0为例 终端命令行检查是否安装成功 node -v npm -vNode.js快速入门 npm设置镜像源 #设置为阿里镜像源 npm config set regist…

精准控图工具 Concept Sliders:超好用的 控制 Lora 适配器

Concept Sliders 你有没有遇到这样的情况&#xff1f;你花费大量时间制作提示和寻找种子&#xff0c;以使用文本到图像模型生成所需的图像。但是&#xff0c;你还需要对生成图像中的属性强度&#xff08;如眼睛大小或照明&#xff09;进行更细致、更精细的控制。修改提示会破坏…

141. 环形链表、142. 环形链表 II

题目 思路 链表无环情况&#xff1a;有空结点 链表有环&#xff1a;有些结点会重复 所以 用集合&#xff08;哈希表&#xff09;来记录遍历的结点 结点不存在&#xff0c;则将结点加到集合中&#xff0c;当遍历到的结点存在集合中&#xff0c;即为链表环开始的结点&#xff0c…

遥控器握杆的几种常见方式!!!

1. 双手持握法 站姿操作&#xff1a;站立时&#xff0c;两脚分开&#xff0c;比肩略宽&#xff0c;以保持身体稳定。双手持握遥控器的两侧&#xff0c;保持放松状态。 细节技巧&#xff1a; 轻轻地用无名指和小指托起遥控器&#xff0c;掌心和遥控器之间留有一定的空隙。 遥…

华为网络多生成树协议

多生成树协议 一个或多个vlan可以映射到同一个生成树中&#xff1b; MSTP将一个网络划分为多个域&#xff0c;每个域有多个生成树&#xff0c;域间利用CIST 公共与内部生成树commonand internal spanning tree 保证拓扑结构无环路&#xff1b; 实例即多个vlan的集合&#xf…