快速整合EasyExcel实现Excel的上传下载
1.EasyExcel
2.Excel的上传(读Excel)
3.Excel的下载(写Excel)
4.结语
1.EasyExcel
首先,这里给出EasyExcel的官方文档:https://easyexcel.opensource.alibaba.com/
alibaba.com不用我多说了吧,大家都认识,这个东西就是阿里开发的:EasyExcel是一个基于Java的、快速、简洁、解决大文件内存溢出的Excel处理工具。
他能让你在不用考虑性能、内存的等因素的情况下,快速完成Excel的读、写等功能。(这段话听着好牛的样子,没错,官方给出的你说呢)
那么由于下面的案例中,涉及到Excel表格的样式问题,所以我这里采用了 EasyExcel
3.1.x的版本。https://easyexcel.opensource.alibaba.com/docs/current/ 开始吧,👇👇👇
2.Excel的上传(读Excel)
我这里首先给大家分享一下SpringBoot结合EasyExcel实现对 Excel 中数据的读取,并且将读取到的数据存入MySQL数据库。
说到这里,要加什么依赖大家肯定都心知肚明了。😄😄😄
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.4</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.9</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.1.1</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.28</version></dependency>
既然要读取Excel,同时存入数据库,那么就必然需要对应的表了,这就引出了 表对应的实体类。 我这里写了两个,这是因为 Excel
对应了一个类,而数据库表对应的是另外一个,原因考虑到可能Excel表格会增加一些不必要的字段,而这些字段并不需要存入数据库中(反过来也是一样,可能数据库实体类中有10个字段,而Excel这边仅有6个字段,而剩余的4个字段我们可能会从其他渠道获取)。
上面我说的可能是在公司实际开发中会遇到的某些场景吧,但是为了方便大家理解,这两个类我还是定义的相同的字段。
package com.distributeredis.redis_springboot.springbooteasyexcel.vo;import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@NoArgsConstructor
@AllArgsConstructor
public class GoodsExcelDTO {@ExcelProperty(index = 0)private Integer id;@ExcelProperty(index = 1)private String name;@ExcelProperty(index = 2)private String info;@ExcelProperty(index = 3)@DateTimeFormat(value = "yyyy-MM-dd HH:mm:ss")private String buyTime;
}
package com.distributeredis.redis_springboot.springbooteasyexcel.vo;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Goods {private Integer id;private String name;private String info;//@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")@DateTimeFormat(value = "yyyy-MM-dd HH:mm:ss")private Date buyTime;
}
Excel对应的类中 buyTime是 String类型,而数据库实体类的 buyTime是Date类型,这是因为:👇👇👇
(阿里官方文档给出的规定)
下面给出goods这张表的sql脚本。
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;-- ----------------------------
-- Table structure for goods
-- ----------------------------
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '商品名称',`info` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '商品信息',`buyTime` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '购买时间',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ----------------------------
-- Records of goods
-- ----------------------------
INSERT INTO `goods` VALUES (1, 'Java核心技术卷I', 'Java四大名著之一', '2021-12-01 13:05:23');
INSERT INTO `goods` VALUES (2, 'Java核心技术卷II', 'Java四大名著之一', '2022-02-28 09:21:55');
INSERT INTO `goods` VALUES (3, 'Java编程思想', 'Java四大名著之一', '2020-05-15 14:16:18');
INSERT INTO `goods` VALUES (4, 'Effective Java', 'Java四大名著之一', '2022-07-06 22:33:44');
INSERT INTO `goods` VALUES (5, '深入理解Java虚拟机', 'JVM由此开始', '2021-06-06 20:59:37');
INSERT INTO `goods` VALUES (6, 'SpringBoot实战应用教程', 'SpringBoot极速开发框架', '2020-03-17 10:02:31');
INSERT INTO `goods` VALUES (7, '快速上手SSM', '一本优秀的书籍', '2021-08-14 19:08:26');
INSERT INTO `goods` VALUES (8, 'MySQL是怎样运行的', '深入学习MySQL', '2022-04-09 15:37:05');
INSERT INTO `goods` VALUES (9, 'Java并发编程', '并发编程之美', '2020-01-18 21:12:13');
INSERT INTO `goods` VALUES (10, 'Java从入门到精通', '小白的Java之路', '2021-09-11 17:18:21');SET FOREIGN_KEY_CHECKS = 1;
大家参考官方文档之后,肯定知道,针对Excel的读,我们需要写一个监听器,去不断的监听读取Excel的每一行数据,最终加入数据库类似这样的操作。
下面就是监听器代码。 有个很重要的点 DemoDataListener
不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去。这也就是监听器中需要声明
private GoodsService goodsService; 这个成员变量的原因。
invoke 方法:解析Excel中的每一条数据都会来调用它。
invokeHead 方法:针对Excel表头的一些操作。
doAfterAllAnalysed 方法:所有数据解析完成了会来调用它。
package com.distributeredis.redis_springboot.springbooteasyexcel.write.goodListener;import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import com.distributeredis.redis_springboot.springbooteasyexcel.vo.Goods;
import com.distributeredis.redis_springboot.springbooteasyexcel.vo.GoodsExcelDTO;
import com.distributeredis.redis_springboot.springbooteasyexcel.write.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;/*** Excel模板的读取类* 有个很重要的点 DemoDataListener 不能被spring管理* 要每次读取excel都要new, 然后里面用到spring可以构造方法传进去*/
@Slf4j
public class GoodsListener implements ReadListener<GoodsExcelDTO> {@Autowiredprivate GoodsService goodsService;private List<GoodsExcelDTO> goodsExcelDTOList = ListUtils.newArrayList();private final List<Goods> goodsList = ListUtils.newArrayList();private int count = 0;public GoodsListener() {}public GoodsListener(GoodsService goodsService) {this.goodsService = goodsService;}@Overridepublic void invoke(GoodsExcelDTO goodsExcelDTO, AnalysisContext analysisContext) {log.info("解析到第 {} 条数据:{}", (++count), JSON.toJSONString(goodsExcelDTO));goodsExcelDTOList.add(goodsExcelDTO);}@Overridepublic void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {Map<Integer, String> stringMap = ConverterUtils.convertToStringMap(headMap, context);Set<Integer> keySet = stringMap.keySet();System.out.println("该Excel表头信息是:");for (int i = 0; i < keySet.size(); i++) {System.out.println("第 " + (i + 1) + " 列 = " + stringMap.get(i));}}@Overridepublic void doAfterAllAnalysed(AnalysisContext analysisContext) {log.info("该Excel的所有数据解析完成!!!");goodsExcelDTOList.forEach(item -> {try {Goods goods = new Goods();goods.setId(item.getId());goods.setName(item.getName());goods.setInfo(item.getInfo());SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date = sdf.parse(item.getBuyTime());goods.setBuyTime(date);goodsList.add(goods);} catch (ParseException e) {log.error(e.getMessage());}});goodsExcelDTOList = ListUtils.newArrayList();goodsService.batchInsert(goodsList);}
}
好的,下面就是我们的mapper、service、controller了。这都是大家很熟悉的东西了。
package com.distributeredis.redis_springboot.springbooteasyexcel.write.mapper;
import com.distributeredis.redis_springboot.springbooteasyexcel.vo.Goods;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface GoodsMapper {/*** 批量插入*/void batchInsert(List<Goods> goodsList);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.distributeredis.redis_springboot.springbooteasyexcel.write.mapper.GoodsMapper"><!-- 使用insert、update、delete、select标签编写sql语句 --><insert id="batchInsert" parameterType="java.util.List">insert into goodsvalues<foreach collection="list" item="item" index="index" separator=",">(#{item.id}, #{item.name}, #{item.info}, #{item.buyTime})</foreach></insert>
</mapper>
package com.distributeredis.redis_springboot.springbooteasyexcel.write.service;
import com.distributeredis.redis_springboot.springbooteasyexcel.vo.Goods;
import java.util.List;
public interface GoodsService {void batchInsert(List<Goods> goodsList);
}
package com.distributeredis.redis_springboot.springbooteasyexcel.write.service.impl;import com.distributeredis.redis_springboot.springbooteasyexcel.vo.Goods;
import com.distributeredis.redis_springboot.springbooteasyexcel.write.mapper.GoodsMapper;
import com.distributeredis.redis_springboot.springbooteasyexcel.write.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService {@Autowiredprivate GoodsMapper goodsMapper;@Override@Transactionalpublic void batchInsert(List<Goods> goodsList) {this.goodsMapper.batchInsert(goodsList);}
}
package com.distributeredis.redis_springboot.springbooteasyexcel.controller;import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.fastjson.JSON;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.service.StudentService;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.StudentExcelDTO;
import com.distributeredis.redis_springboot.springbooteasyexcel.vo.GoodsExcelDTO;
import com.distributeredis.redis_springboot.springbooteasyexcel.write.goodListener.GoodsListener;
import com.distributeredis.redis_springboot.springbooteasyexcel.write.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;@RestController
@RequestMapping(value = "/excel")
public class EasyExcelController {@Autowiredprivate GoodsService goodsService;@Autowiredprivate StudentService studentService;/*** 文件excel上传*/@PostMapping(value = "/upload")public String upload(MultipartFile file) throws Exception {EasyExcel.read(file.getInputStream(), GoodsExcelDTO.class, new GoodsListener(goodsService)).sheet().headRowNumber(1).doRead();return "success";}/*** Excel文件下载*/@GetMapping(value = "/download")public void download(HttpServletResponse response) throws IOException {response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.setCharacterEncoding("utf-8");//这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系String fileName = URLEncoder.encode("学生信息表", "UTF-8").replaceAll("\\+", "%20");response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");List<StudentExcelDTO> studentList = studentService.queryAllStudents();EasyExcel.write(response.getOutputStream(), StudentExcelDTO.class).sheet("sheet1").doWrite(studentList);}/*** Excel文件下载并且失败的时候返回json*/@GetMapping(value = "/downloadFailedUsingJson")public void downloadFailedUsingJson(HttpServletResponse response) throws IOException {try {response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.setCharacterEncoding("utf-8");//这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系String fileName = URLEncoder.encode("学生信息表", "UTF-8").replaceAll("\\+", "%20");response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");List<StudentExcelDTO> studentList = studentService.queryAllStudents();EasyExcel.write(response.getOutputStream(), StudentExcelDTO.class).autoCloseStream(Boolean.FALSE).sheet("sheet1").doWrite(studentList);} catch (Exception e) {//重置responseresponse.reset();response.setContentType("application/json");response.setCharacterEncoding("utf-8");Map<String, String> map = MapUtils.newHashMap();map.put("status", "failure");map.put("message", "Excel文件下载失败" + e.getMessage());response.getWriter().println(JSON.toJSONString(map));}}
}
再然后就是SpringBoot的核心配置文件和主启动类。
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/mysql_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=falseusername: rootpassword: 123456application:name: RedisDemo#Redis????redis:host: localhostport: 6379#password: 123456database: 0 #????0????jedis:#Redis?????pool:max-active: 8 #?????max-wait: 1ms #???????????max-idle: 4 #???????????min-idle: 0 #???????????
由于这是上传操作,所以我这里也给大家提供我创建的Excel文档。可以看到和上面的goods表的字段都是对应好的。
下面我们启动项目,在postman中对上传Excel接口进行测试。
3.Excel的下载(写Excel)
这里仍然用到的和上面的读Excel是同一个SpringBoot项目,所以依赖、核心配置文件、主启动类这些都是一样的,就不再给出了,大家参考上面的就行了。
那么对于Excel的下载,也就是说向Excel中写入数据,相较于上传操作就要简单多了。 来看下面的步骤:👇👇👇
这里模拟的场景是:从数据库中的某张表获取到对应的数据集,然后将这个List集合写入Excel中。
所以自然也是需要实体类,那么和上面的上传操作一样,我仍然是创建两个类,一个是Excel表格对应的实体类,另一个是我们数据库对应的实体类。
package com.distributeredis.redis_springboot.springbooteasyexcel.read.vo;import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.*;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;/*** 类上面的注解,来自lombok和EasyExcel官方,用来自定义表头、宽度等信息*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ColumnWidth(25)
@HeadRowHeight(30)
@ContentRowHeight(20)
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)
@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)
public class StudentExcelDTO {@ExcelProperty({"学生综述", "学生编号"})private Integer id;@ExcelProperty({"学生综述", "学生姓名"})private String name;@ExcelProperty({"学生综述", "学生年龄"})private Integer age;@ExcelProperty({"学生综述", "学生爱好"})private String hobby;@ExcelIgnoreprivate String address;
}
package com.distributeredis.redis_springboot.springbooteasyexcel.read.vo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;/****/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {private Integer id;private String name;private Integer age;private String hobby;private String address;
}
student这张表的sql脚本,我也给到大家。
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键,暂定学生编号',`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '学生姓名',`age` int(11) NOT NULL COMMENT '学生年龄',`hobby` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '学生爱好',`address` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '学生住址',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES (1, '张三', 41, '睡觉', '湖北省武汉市');
INSERT INTO `student` VALUES (2, '李四', 66, '吃饭', '湖南省长沙市');
INSERT INTO `student` VALUES (3, '王五', 28, '打游戏', '江苏省南京市');
INSERT INTO `student` VALUES (4, '赵六', 35, '玩手机', '浙江省杭州市');
INSERT INTO `student` VALUES (5, '田七', 52, '旅游', '上海市黄浦区');
INSERT INTO `student` VALUES (6, '小哥', 22, '盗墓', '河南省洛阳市');
INSERT INTO `student` VALUES (7, '张起灵', 18, '倒斗', '北京市海淀区');
INSERT INTO `student` VALUES (8, '闷油瓶', 20, '挖坟', '广东省深圳市');SET FOREIGN_KEY_CHECKS = 1;
下面就是我们的mapper、service、controller了,还是大家熟悉的那一套。
package com.distributeredis.redis_springboot.springbooteasyexcel.read.mapper;import com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.Student;
import org.apache.ibatis.annotations.Mapper;import java.util.List;@Mapper
public interface StudentMapper {/*** 获取学生列表*/List<Student> queryAllStudents();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.distributeredis.redis_springboot.springbooteasyexcel.read.mapper.StudentMapper"><!-- 使用insert、update、delete、select标签编写sql语句 --><sql id="student_column_list">id, name, age, hobby, address</sql><resultMap id="studentMap" type="com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.Student"><id column="id" property="id"></id><result column="name" property="name"></result><result column="age" property="age"></result><result column="hobby" property="hobby"></result><result column="address" property="address"></result></resultMap><select id="queryAllStudents" resultMap="studentMap">select <include refid="student_column_list"/>from student</select></mapper>
package com.distributeredis.redis_springboot.springbooteasyexcel.read.service;import com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.StudentExcelDTO;import java.util.List;/****/
public interface StudentService {List<StudentExcelDTO> queryAllStudents();
}
package com.distributeredis.redis_springboot.springbooteasyexcel.read.service.impl;import com.distributeredis.redis_springboot.springbooteasyexcel.read.mapper.StudentMapper;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.service.StudentService;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.Student;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.StudentExcelDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class StudentServiceImpl implements StudentService {@Autowiredprivate StudentMapper studentMapper;@Overridepublic List<StudentExcelDTO> queryAllStudents() {List<Student> studentList = studentMapper.queryAllStudents();List<StudentExcelDTO> students = new ArrayList<>();studentList.forEach(item -> {StudentExcelDTO student = new StudentExcelDTO();BeanUtils.copyProperties(item, student);students.add(student);});return students;}
}
核心配置文件、主启动类这些都是和上面的案例一样的,就不再给出了。 下面直接启动项目,在postman中进行测试。
这里大家注意一下,有的小伙伴可能直接点了Send,然后postman反馈了一堆乱码,但是此时把接口地址拿到浏览器中是可以直接访问的。
解决办法就是:点击下图中的 Send and Download。


保存之后,我们的Excel下载接口就可以正常跑通,下面就是下载成功的Excel了。😄😄😄
4.结语
> 上面的两个案例就是SpringBoot整合EasyExcel,实现Excel的读写(上传下载)的操作。
> 我这里所有的整合步骤均来自阿里的EasyExcel官方文档,所以大家有什么疑问都可以去官方文档中查找,地址在文章开头已经给出了。
> 或者大家也可以在文章下面评论,我都会一一回复的,和大家一起讨论技术话题。😄😄😄 ```
相关文章:
快速整合EasyExcel实现Excel的上传下载
1.EasyExcel 2.Excel的上传(读Excel) 3.Excel的下载(写Excel) 4.结语 1.EasyExcel 首先,这里给出EasyExcel的官方文档:https://easyexcel.opensource.alibaba.com/ alibaba.com不用我多说了吧,大…...
MongoDB的条件操作符
本文主要介绍MongoDB的条件操作符。 目录 MongoDB条件操作符1.比较操作符2.逻辑操作符3.元素操作符4.数组操作符5.文本搜索操作符 MongoDB条件操作符 MongoDB的条件操作符主要分为比较操作符、逻辑操作符、元素操作符、数组操作符、文本搜索操作符等几种类型。 以下是这些操作…...
【Linux】探索Linux进程状态 | 僵尸进程 | 孤儿进程
最近,我发现了一个超级强大的人工智能学习网站。它以通俗易懂的方式呈现复杂的概念,而且内容风趣幽默。我觉得它对大家可能会有所帮助,所以我在此分享。点击这里跳转到网站。 目录 一、进程状态1.1运行状态1.2阻塞状态1.3挂起状态 二、具体L…...
大数据股票简单分析
目录标题 内容说明解题量化金融的含义量化交易策略 点击直接资料领取 内容 1解释量化金融的含义,调研并给出至少 5种量化交易的策略或方法 2.完成Tushare Pro 的安装、注册,获取自己的 Token,查阅网站内的接口讲解和示例; 3通过Python 编程完…...
从零开始搭建链上dex自动化价差套利程序(11)
风险控制 需要将仓位杠杆控制到3倍以内,由于dydx与apex没有获取仓位杠杆的接口,但是每次发送交易的数额可以决定,故而可以设置每次发送总仓位1.5倍杠杆的数额,然后设置一个变量保证每个方向上的交易不超过2次,即可保证…...
2023.12面试题汇总小结
文章目录 Java字节码都包括哪些内容Java双亲委派机制如何打破Java Memory Model是什么synchronized的锁优化是什么CountDownLatch、CyclicBarrier、Semaphore有啥区别,什么场景下使用MySQL MVCC原理MySQL RR隔离级别,会出现幻读吗MySQL的RR隔离级别下&am…...
Linux权限命令详解
Linux权限命令详解 文章目录 Linux权限命令详解一、什么是权限?二、权限的本质三、Linux中的用户四、linux中文件的权限4.1 文件访问者的分类(人)4.2 文件类型和访问权限(事物属性) 五、快速掌握修改权限的做法【第一种…...
【Android】Glide的简单使用(下)
文章目录 缓存设置内存缓存硬盘缓存自定义磁盘缓存行为图片请求优先级缩略图旋转图片Glide的回调:TargetsBaseTargetTarget注意事项设置具体尺寸的Target 调试及Debug获取异常信息 配置第三方网络库自定义缓存 缓存设置 GlideApp .with(context).load(gifUrl).asGif().error(…...
TCP对数据的拆分
应用程序的数据一般都比较大,因此TCP会按照网络包的大小对数据进行拆分。 当发送缓冲区中的数据超过MSS的长度,数据会被以MSS长度为单位进行拆分,拆分出来的数据块被放进单独的网路包中。 根据发送缓冲区中的数据拆分情况,当判断…...
面试问题--计算机网络:二层转发、三层转发与osi模型
计算机网络:二层转发、三层转发与OSI模型 1. 二层转发和三层转发 1.1 二层转发(Data Link Layer) 在计算机网络中,二层转发是通过数据链路层(Data Link Layer)实现的。以下是关于二层转发的一些关键信息…...
kubectl获取ConfigMap导出YAML时如何忽略某些字段
前言: 当我们在使用Kubernetes时,常常需要通过kubectl命令行工具来管理资源。有时我们也想将某个资源的配置导出为YAML文件,这样做有助于版本控制和资源的迁移。然而,默认情况下,使用kubectl get命令导出资源配置会包…...
复制粘贴——QT实现原理
复制粘贴——QT实现原理 QT 剪贴板相关类 QClipboard 对外通用的剪贴板类,一般通过QGuiApplication::clipboard() 来获取对应的剪贴板实例。 // qtbase/src/gui/kernel/qclipboard.h class Q_GUI_EXPORT QClipboard : public QObject {Q_OBJECT private:explici…...
(一)五种最新算法(SWO、COA、LSO、GRO、LO)求解无人机路径规划MATLAB
一、五种算法(SWO、COA、LSO、GRO、LO)简介 1、蜘蛛蜂优化算法SWO 蜘蛛蜂优化算法(Spider wasp optimizer,SWO)由Mohamed Abdel-Basset等人于2023年提出,该算法模型雌性蜘蛛蜂的狩猎、筑巢和交配行为&…...
LED透镜粘接UV胶是一种特殊的UV固化胶,用于固定和粘合LED透镜。
LED透镜粘接UV胶是一种特殊的UV固化胶,用于固定和粘合LED透镜。 它具有以下特点: 1. 高透明度:LED透镜粘接UV胶具有高透明度,可以确保光线的透过性,不影响LED的亮度和效果。 2. 快速固化:经过UV紫外线照射…...
C语言 题目
1.写一个函数算一个数的二进制(补码)表示中有几个1 #include<stdio.h>//统计二进制数中有几个1 //如13:1101 //需要考虑负数情况 如-1 结果应该是32// n 1101 //n-1 1100 //n 1100 //n-1 1011 //n 1000 //n-1 0111 //n 0000 //看n的变化 int funca(int c){int co…...
CDN 内容分发网络
CDN常见问题 什么是 CDN ? CDN 全称是 Content Delivery Network/Content Distribution Network,翻译过的意思是 内容分发网络 。 我们可以将内容分发网络拆开来看: 内容:指的是静态资源比如图片、视频、文档、JS、CSS、HTML。…...
Android : Xui- RecyclerView+BannerLayout 轮播图简单应用
实例图: 1.引用XUI http://t.csdnimg.cn/Wb4KR 2.创建显示图片布局 banner_item.xml <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"…...
Java网络通信-第21章
Java网络通信-第21章 1.网络程序设计基础 网络程序设计基础涵盖了许多方面,包括网络协议、Web开发、数据库连接、安全性等。 1.1局域网与互联网 局域网(LAN)与互联网(Internet)是两个不同的概念,它们分…...
Leetcode 345. Reverse Vowels of a String
Problem Given a string s, reverse only all the vowels in the string and return it. The vowels are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’, and they can appear in both lower and upper cases, more than once. Algorithm Collect all the vowels and reverse the…...
[linux] 用命令行wget下载google drive的大文件
使用wget命令下载Google drive上的文件_ubuntu上wget下载谷歌云盘文件-CSDN博客 如何用命令行下载Google Drive上的共享文件?-腾讯云开发者社区-腾讯云 举例:https://drive.google.com/drive/folders/1vKj3VvJEKgS_o-uOSmz3I0-GomECpql3 1、在网页上&…...
JavaSec-RCE
简介 RCE(Remote Code Execution),可以分为:命令注入(Command Injection)、代码注入(Code Injection) 代码注入 1.漏洞场景:Groovy代码注入 Groovy是一种基于JVM的动态语言,语法简洁,支持闭包、动态类型和Java互操作性,…...
【网络】每天掌握一个Linux命令 - iftop
在Linux系统中,iftop是网络管理的得力助手,能实时监控网络流量、连接情况等,帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...
K8S认证|CKS题库+答案| 11. AppArmor
目录 11. AppArmor 免费获取并激活 CKA_v1.31_模拟系统 题目 开始操作: 1)、切换集群 2)、切换节点 3)、切换到 apparmor 的目录 4)、执行 apparmor 策略模块 5)、修改 pod 文件 6)、…...
Spring Boot 实现流式响应(兼容 2.7.x)
在实际开发中,我们可能会遇到一些流式数据处理的场景,比如接收来自上游接口的 Server-Sent Events(SSE) 或 流式 JSON 内容,并将其原样中转给前端页面或客户端。这种情况下,传统的 RestTemplate 缓存机制会…...
以下是对华为 HarmonyOS NETX 5属性动画(ArkTS)文档的结构化整理,通过层级标题、表格和代码块提升可读性:
一、属性动画概述NETX 作用:实现组件通用属性的渐变过渡效果,提升用户体验。支持属性:width、height、backgroundColor、opacity、scale、rotate、translate等。注意事项: 布局类属性(如宽高)变化时&#…...
汽车生产虚拟实训中的技能提升与生产优化
在制造业蓬勃发展的大背景下,虚拟教学实训宛如一颗璀璨的新星,正发挥着不可或缺且日益凸显的关键作用,源源不断地为企业的稳健前行与创新发展注入磅礴强大的动力。就以汽车制造企业这一极具代表性的行业主体为例,汽车生产线上各类…...
macOS多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用
文章目录 问题现象问题原因解决办法 问题现象 macOS启动台(Launchpad)多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用。 问题原因 很明显,都是Google家的办公全家桶。这些应用并不是通过独立安装的…...
ElasticSearch搜索引擎之倒排索引及其底层算法
文章目录 一、搜索引擎1、什么是搜索引擎?2、搜索引擎的分类3、常用的搜索引擎4、搜索引擎的特点二、倒排索引1、简介2、为什么倒排索引不用B+树1.创建时间长,文件大。2.其次,树深,IO次数可怕。3.索引可能会失效。4.精准度差。三. 倒排索引四、算法1、Term Index的算法2、 …...
自然语言处理——循环神经网络
自然语言处理——循环神经网络 循环神经网络应用到基于机器学习的自然语言处理任务序列到类别同步的序列到序列模式异步的序列到序列模式 参数学习和长程依赖问题基于门控的循环神经网络门控循环单元(GRU)长短期记忆神经网络(LSTM)…...
C++ Visual Studio 2017厂商给的源码没有.sln文件 易兆微芯片下载工具加开机动画下载。
1.先用Visual Studio 2017打开Yichip YC31xx loader.vcxproj,再用Visual Studio 2022打开。再保侟就有.sln文件了。 易兆微芯片下载工具加开机动画下载 ExtraDownloadFile1Info.\logo.bin|0|0|10D2000|0 MFC应用兼容CMD 在BOOL CYichipYC31xxloaderDlg::OnIni…...






