SpringBoot 整合 MongoDB 实现数据的增删改查!
一、介绍
在 MongoDB 中有三个比较重要的名词:数据库、集合、文档!
数据库(Database):和关系型数据库一样,每个数据库中有自己的用户权限,不同的项目组可以使用不同的数据库
集合(Collection): 集合指的是文档组(类似于 Mysql 中的表的概念),里面可以存储许多文档
文档(Document): 文档是 MongoDB 中最基本的数据单元,由键值对组成,类似于 JSON 格式,可以存储不同字段,字段的值可以包括其他文档、数组和文档数组
搞懂这三个名词,基本就可以上手了,今天我们以 SpringBoot 整合 MongoDB 为例,实现数据的增删改查
话不多说,直接开撸!
二、代码实践
2.1、创建 SpringBoot 工程,添加 MongoDB 依赖包
<!-- 引入springboot -->
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.0.RELEASE</version>
</parent><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>2.2、添加配置文件
在application.properties文件中添加mongodb相关配置!
#配置数据库连接地址
spring.data.mongodb.uri=mongodb://userName:password@127.0.0.1:27017/dbName相关参数说明:
userName:表示用户名,根据实际情况填写即可
password:表示用户密码,根据实际情况填写即可
dbName:表示数据库,可以自定义,初始化数据的时候,会自动创建
2.3、创建实体类
创建一个实体类Person,其中注解@Document(collection="persons")表示当前实体类对应的集合名称是persons,类似于关系型数据库中的表名称。
注解@Id表示当前字段,在集合结构中属于主键类型。
/*** 使用@Document注解指定集合名称*/
@Document(collection="persons")
public class Person implements Serializable {private static final long serialVersionUID = -3258839839160856613L;/*** 使用@Id注解指定MongoDB中的 _id 主键*/@Idprivate Long id;private String userName;private String passWord;private Integer age;private Date createTime;//...get/set@Overridepublic String toString() {return "Person{" +"id=" + id +", userName='" + userName + '\'' +", passWord='" + passWord + '\'' +", age=" + age +", createTime=" + createTime +'}';}
}2.4、操作 MongoDB
Springboot 操作 MongoDB 有两种方式。
第一种方式是采用 Springboot 官方推荐的 JPA 方式,这种操作方式,使用简单但是灵活性比较差。
第二种方式是采用 Spring Data MongoDB 基于 MongoDB 官方 Java API 封装的 MongoTemplate 操作类对 MongoDB 进行操作,这种方式非常灵活,能满足绝大部分需求。
本文将采用第二种方式进行介绍!
2.5、插入文档
MongoTemplate提供了insert()方法,用于插入文档,示例代码如下:
用于插入文档
没指定集合名称时,会取@Document注解中的集合名称
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 插入文档* @throws Exception*/@Testpublic void insert() throws Exception {Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());mongoTemplate.insert(person);}
}自定义集合名称,插入文档
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 自定义集合,插入文档* @throws Exception*/@Testpublic void insertCustomCollection() throws Exception {Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());mongoTemplate.insert(person, "custom_person");}
}自定义集合,批量插入文档
如果采用批量插入文档,必须指定集合名称
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 自定义集合,批量插入文档* @throws Exception*/@Testpublic void insertBatch() throws Exception {List<Person> personList = new ArrayList<>();Person person1 =new Person();person1.setId(10l);person1.setUserName("张三");person1.setPassWord("123456");person1.setCreateTime(new Date());personList.add(person1);Person person2 =new Person();person2.setId(11l);person2.setUserName("李四");person2.setPassWord("123456");person2.setCreateTime(new Date());personList.add(person2);mongoTemplate.insert(personList, "custom_person");}
}2.6、存储文档
MongoTemplate提供了save()方法,用于存储文档。
在存储文档的时候会通过主键 ID 进行判断,如果存在就更新,否则就插入,示例代码如下:
存储文档,如果没有插入,否则通过主键ID更新
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 存储文档,如果没有插入,否则更新* @throws Exception*/@Testpublic void save() throws Exception {Person person =new Person();person.setId(13l);person.setUserName("八八");person.setPassWord("123456");person.setAge(40);person.setCreateTime(new Date());mongoTemplate.save(person);}
}自定义集合,存储文档
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 自定义集合,存储文档* @throws Exception*/@Testpublic void saveCustomCollection() throws Exception {Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());mongoTemplate.save(person, "custom_person");}
}2.7、更新文档
MongoTemplate提供了updateFirst()和updateMulti()方法,用于更新文档,示例代码如下:
更新文档,匹配查询到的文档数据中的第一条数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 更新文档,匹配查询到的文档数据中的第一条数据* @throws Exception*/@Testpublic void updateFirst() throws Exception {//更新对象Person person =new Person();person.setId(1l);person.setUserName("张三123");person.setPassWord("123456");person.setCreateTime(new Date());//更新条件Query query= new Query(Criteria.where("id").is(person.getId()));//更新值Update update= new Update().set("userName", person.getUserName()).set("passWord", person.getPassWord());//更新查询满足条件的文档数据(第一条)UpdateResult result =mongoTemplate.updateFirst(query,update, Person.class);if(result!=null){System.out.println("更新条数:" + result.getMatchedCount());}}
}更新文档,匹配查询到的文档数据中的所有数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 更新文档,匹配查询到的文档数据中的所有数据* @throws Exception*/@Testpublic void updateMany() throws Exception {//更新对象Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());//更新条件Query query= new Query(Criteria.where("id").is(person.getId()));//更新值Update update= new Update().set("userName", person.getUserName()).set("passWord", person.getPassWord());//更新查询满足条件的文档数据(全部)UpdateResult result = mongoTemplate.updateMulti(query, update, Person.class);if(result!=null){System.out.println("更新条数:" + result.getMatchedCount());}}
}2.8、删除文档
MongoTemplate提供了remove()、findAndRemove()和findAllAndRemove()方法,用于删除文档,示例代码如下:
删除符合条件的所有文档
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 更新文档,匹配查询到的文档数据中的所有数据* @throws Exception*/@Testpublic void updateMany() throws Exception {//更新对象Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());//更新条件Query query= new Query(Criteria.where("id").is(person.getId()));//更新值Update update= new Update().set("userName", person.getUserName()).set("passWord", person.getPassWord());//更新查询满足条件的文档数据(全部)UpdateResult result = mongoTemplate.updateMulti(query, update, Person.class);if(result!=null){System.out.println("更新条数:" + result.getMatchedCount());}}
}删除符合条件的单个文档,并返回删除的文档
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 删除符合条件的单个文档,并返回删除的文档* @throws Exception*/@Testpublic void findAndRemove() throws Exception {Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());Query query = new Query(Criteria.where("id").is(person.getId()));Person result = mongoTemplate.findAndRemove(query, Person.class);System.out.println("删除的文档数据:" + result.toString());}
}删除符合条件的所有文档,并返回删除的文档
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 删除符合条件的所有文档,并返回删除的文档* @throws Exception*/@Testpublic void findAllAndRemove() throws Exception {Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());Query query = new Query(Criteria.where("id").is(person.getId()));List<Person> result = mongoTemplate.findAllAndRemove(query, Person.class);System.out.println("删除的文档数据:" + result.toString());}
}2.9、查询文档
MongoTemplate提供了非常多的文档查询方法,日常开发中用的最多的就是find()方法,示例代码如下:
查询集合中的全部文档数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 查询集合中的全部文档数据* @throws Exception*/@Testpublic void findAll() throws Exception {List<Person> result = mongoTemplate.findAll(Person.class);System.out.println("查询结果:" + result.toString());}
}查询集合中指定的ID文档数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 查询集合中指定的ID文档数据* @throws Exception*/@Testpublic void findById() {long id = 1l;Person result = mongoTemplate.findById(id, Person.class);System.out.println("查询结果:" + result.toString());}
}根据条件查询集合中符合条件的文档,返回第一条数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据条件查询集合中符合条件的文档,返回第一条数据*/@Testpublic void findOne() {String userName = "张三";Query query = new Query(Criteria.where("userName").is(userName));Person result = mongoTemplate.findOne(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据条件查询集合中符合条件的文档
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据条件查询集合中符合条件的文档*/@Testpublic void findByCondition() {String userName = "张三";Query query = new Query(Criteria.where("userName").is(userName));List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据【AND】关联多个查询条件,查询集合中的文档数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据【AND】关联多个查询条件,查询集合中的文档数据*/@Testpublic void findByAndCondition() {// 创建条件Criteria criteriaUserName = Criteria.where("userName").is("张三");Criteria criteriaPassWord = Criteria.where("passWord").is("123456");// 创建条件对象,将上面条件进行 AND 关联Criteria criteria = new Criteria().andOperator(criteriaUserName, criteriaPassWord);// 创建查询对象,然后将条件对象添加到其中Query query = new Query(criteria);List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据【OR】关联多个查询条件,查询集合中的文档数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据【OR】关联多个查询条件,查询集合中的文档数据*/@Testpublic void findByOrCondition() {// 创建条件Criteria criteriaUserName = Criteria.where("userName").is("张三");Criteria criteriaPassWord = Criteria.where("passWord").is("123456");// 创建条件对象,将上面条件进行 OR 关联Criteria criteria = new Criteria().orOperator(criteriaUserName, criteriaPassWord);// 创建查询对象,然后将条件对象添加到其中Query query = new Query(criteria);List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据【IN】关联多个查询条件,查询集合中的文档数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据【IN】关联多个查询条件,查询集合中的文档数据*/@Testpublic void findByInCondition() {// 设置查询条件参数List<Long> ids = Arrays.asList(1l, 10l, 11l);// 创建条件Criteria criteria = Criteria.where("id").in(ids);// 创建查询对象,然后将条件对象添加到其中Query query = new Query(criteria);List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据【逻辑运算符】查询集合中的文档数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据【逻辑运算符】查询集合中的文档数据*/@Testpublic void findByOperator() {// 设置查询条件参数int min = 20;int max = 35;Criteria criteria = Criteria.where("age").gt(min).lte(max);// 创建查询对象,然后将条件对象添加到其中Query query = new Query(criteria);List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据【正则表达式】查询集合中的文档数据
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据【正则表达式】查询集合中的文档数据*/@Testpublic void findByRegex() {// 设置查询条件参数String regex = "^张*";Criteria criteria = Criteria.where("userName").regex(regex);// 创建查询对象,然后将条件对象添加到其中Query query = new Query(criteria);List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据条件查询集合中符合条件的文档,获取其文档列表并排序
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据条件查询集合中符合条件的文档,获取其文档列表并排序*/@Testpublic void findByConditionAndSort() {String userName = "张三";Query query = new Query(Criteria.where("userName").is(userName)).with(Sort.by("age"));List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}根据单个条件查询集合中的文档数据,并按指定字段进行排序与限制指定数目
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据单个条件查询集合中的文档数据,并按指定字段进行排序与限制指定数目*/@Testpublic void findByConditionAndSortLimit() {String userName = "张三";//从第一行开始,查询2条数据返回Query query = new Query(Criteria.where("userName").is(userName)).with(Sort.by("createTime")).limit(2).skip(1);List<Person> result = mongoTemplate.find(query, Person.class);System.out.println("查询结果:" + result.toString());}
}统计集合中符合【查询条件】的文档【数量】
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 统计集合中符合【查询条件】的文档【数量】*/@Testpublic void countNumber() {// 设置查询条件参数String regex = "^张*";Criteria criteria = Criteria.where("userName").regex(regex);// 创建查询对象,然后将条件对象添加到其中Query query = new Query(criteria);long count = mongoTemplate.count(query, Person.class);System.out.println("统计结果:" + count);}
}3.0、索引管理
索引在所有的数据库中,暂居的位置非常重要,例如当你检索一张上百万的数据表的时候,如果没走索引,查询效率会极其缓慢,对于 MongoDB 来说,同样如此。
示例如下:
创建升序索引
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 创建升序索引*/@Testpublic void createAscendingIndex() {// 设置字段名称String field = "userName";// 创建索引mongoTemplate.getCollection("persons").createIndex(Indexes.ascending(field));}
}移除索引
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 根据索引名称移除索引*/@Testpublic void removeIndex() {// 设置字段名称String field = "userName";// 删除索引mongoTemplate.getCollection("persons").dropIndex(field);}
}查询集合中所有的索引
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonServiceTest {@Autowiredprivate MongoTemplate mongoTemplate;/*** 查询集合中所有的索引*/@Testpublic void getIndexAll() {// 获取集合中所有列表ListIndexesIterable<Document> indexList = mongoTemplate.getCollection("persons").listIndexes();// 获取集合中全部索引信息for (Document document : indexList) {System.out.println("索引列表:" + document);}}
}我们还可以通过在实体类上加注解方式来创建索引
/*** 使用@Document注解指定集合名称*/
@Document(collection="persons")
public class Person implements Serializable {private static final long serialVersionUID = -3258839839160856613L;/*** 使用@Id注解指定MongoDB中的 _id 主键*/@Idprivate Long id;private String userName;private String passWord;private Integer age;/*** 创建一个5秒之后文档自动删除的索引*/@Indexed(expireAfterSeconds=5)private Date createTime;//...get/set@Overridepublic String toString() {return "Person{" +"id=" + id +", userName='" + userName + '\'' +", passWord='" + passWord + '\'' +", age=" + age +", createTime=" + createTime +'}';}
}3.1、引入 MongoDB 中的事务
单节点 mongodb 不支持事务,需要搭建 MongoDB 复制集。
/*** 配置事务管理器**/
@Configuration
public class TransactionConfig {@BeanMongoTransactionManager transactionManager(MongoDatabaseFactory dbFactory) {return new MongoTransactionManager(dbFactory);}}事务服务测试!
@Service
public class TransactionExample {@Autowiredprivate MongoTemplate mongoTemplate;@Transactional(rollbackFor = Exception.class)public Object transactionTest(){Person person =new Person();person.setId(1l);person.setUserName("张三");person.setPassWord("123456");person.setCreateTime(new Date());Person newPerson = mongoTemplate.insert(person);// 测试抛出异常,观察数据是否进行回滚if(1 == 1){throw new RuntimeException("异常");}return newPerson;}
}三、小结
本文主要围绕 SpringBoot 整合 MongoDB 实现数据的增删改查操作进行基本介绍,如果有描述不对的,还原网友留言指出!
在实际的业务场景中,可能还需要用到聚合函数等高级查询,大家如果有这种需求,可以访问如下地址获取更加详细的 api 文档介绍:MongoDB 文档查询 api 介绍
相关文章:
SpringBoot 整合 MongoDB 实现数据的增删改查!
一、介绍在 MongoDB 中有三个比较重要的名词:数据库、集合、文档!数据库(Database):和关系型数据库一样,每个数据库中有自己的用户权限,不同的项目组可以使用不同的数据库集合(Colle…...
VUE前端常问面试题
文章目录一、VUE前端常问面试题二、文档下载地址一、VUE前端常问面试题 1、MVC和MVVM 区别 MVC:MVC全名是 Model View Controller,即模型-视图-控制器的缩写,一种软件设计典范。 Model(模型):是用于处理应用程序数据逻辑部分。通…...
c++中map/unordered_map的不同遍历方式以及结构化绑定
文章目录方式一:值传递遍历方式二:引用传递遍历方式三:使用迭代器遍历方式四:结构化绑定(c17特性)结构化绑定示例(1)元组tuple结构化绑定(2)结构体结构化绑定(3ÿ…...
Kafka系列之:Kraft模式
Kafka系列之:Kraft模式 一、Kraft架构二、Kafka的Kraft集群部署三、初始化集群数据目录四、创建KafkaTopic五、查看Kafka Topic六、创建生产者七、创建消费者一、Kraft架构 Kafka元数据存储在zookeeper中,运行时动态选举controller,由controller进行Kafka集群管理。Kraft模式…...
动态规划:leetcode 139.单词拆分、多重背包问题
leetcode 139.单词拆分leetcode 139.单词拆分给定一个非空字符串 s 和一个包含非空单词的列表 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。说明:拆分时可以重复使用字典中的单词。你可以假设字典中没有重复的单词。示例 1&…...
Stable Diffusion原理详解
Stable Diffusion原理详解 最近AI图像生成异常火爆,听说鹅厂都开始用AI图像生成做前期设定了,小厂更是直接用AI替代了原画师的岗位。这一张张丰富细腻、风格各异、以假乱真的AI生成图像,背后离不开Stable Diffusion算法。 Stable Diffusion…...
webpack高级配置
摇树(tree shaking) 我主要是想说摇树失败的原因(tree shaking 失败的原因),先讲下摇树本身效果 什么是摇树? 举个例子 首先 webpack.config.js配置 const webpack require("webpack");/**…...
jQuery 事件
jQuery 事件 Date: February 28, 2023 Sum: jQuery事件注册、处理、对象 目标: 能够说出4种常见的注册事件 能够说出 on 绑定事件的优势 能够说出 jQuery 事件委派的优点以及方式 能够说出绑定事件与解绑事件 jQuery 事件注册 单个时间注册 语法:…...
【批处理脚本】-2.3-解析地址命令arp
"><--点击返回「批处理BAT从入门到精通」总目录--> 共2页精讲(列举了所有arp的用法,图文并茂,通俗易懂) 目录 1 arp命令解析 1.1 询问当前协议数据,显示当前 ARP 项...
改进 YOLO V5 的密集行人检测算法研究(论文研读)——目标检测
改进 YOLO V5 的密集行人检测算法研究(2021.08)摘 要:1 YOLO V52 SENet 通道注意力机制3 改进的 YOLO V5 模型3.1 训练数据处理改进3.2 YOLO V5 网络改进3.3 损失函数改进3.3.1 使用 CIoU3.3.2 非极大值抑制改进4 研究方案与结果分析4.1 实验…...
Python - Opencv应用实例之CT图像检测边缘和内部缺陷
Python - Opencv应用实例之CT图像检测边缘和内部缺陷 将传统图像处理处理算法应用于CT图像的边缘检测和缺陷检测,想要实现效果如下: 关于图像处理算法,主要涉及的有:灰度、阈值化、边缘或角点等特征提取、灰度相似度变换,主要偏向于一些2D的几何变换、涉及图像矩阵的一些统…...
管理逻辑备数据库(Logical Standby Database)
1. SQL Apply架构概述 SQL Apply使用一组后台进程来应用来自主数据库的更改到逻辑备数据库。 在日志挖掘和应用处理中涉及到的不同的进程和它们的功能如下: 在日志挖掘过程中: 1)READER进程从归档redo日志文件或备redo日志文件中读取redo记…...
【C++】构造函数(初始化列表)、explicit、 Static成员、友元、内部类、匿名对象
构造函数(初始化列表)前提构造函数体赋值初始化列表explicit关键字static成员概念特性(重要)有元友元函数友元类内部类匿名对象构造函数(初始化列表) 前提 前面 六个默认成员对象中我们已经学过什么是构造…...
(六十)再来看看几个最常见和最基本的索引使用规则
今天我们来讲一下最常见和最基本的几个索引使用规则,也就是说,当我们建立好一个联合索引之后,我们的SQL语句要怎么写,才能让他的查询使用到我们建立好的索引呢? 下面就一起来看看,还是用之前的例子来说明。…...
机器学习与目标检测作业(数组相加:形状需要满足哪些条件)
机器学习与目标检测(数组相加:形状需要满足哪些条件)机器学习与目标检测(数组相加:形状需要满足哪些条件)一、形状相同1.1、形状相同示例程序二、符合广播机制2.1、符合广播机制的描述2.2、符合广播机制的示例程序机器学习与目标检…...
CentOS救援模式(Rescue Mode)及紧急模式(Emergency Mode)
当CentOS操作系统崩溃,无法正常启动时,可以通过救援模式或者紧急模式进行系统登录。启动CentOS, 当出现下面界面时,按e进入编辑界面。在编辑界面里,加入参数:systemd.unitrescue.target ,然后Ctrl-X启动进入…...
从面试官角度告诉你高级性能测试工程师面试必问的十大问题
目录 1、介绍下最近做过的项目,背景、预期指标、系统架构、场景设计及遇到的性能问题,定位分析及优化; 2、项目处于什么阶段适合性能测试介入,原因是什么? 3、性能测试场景设计要考虑哪些因素? 4、对于一…...
通过知识库深度了解用户的心理
自助服务知识库的价值是毋庸置疑的,如果执行得当,可以帮助减少客户服务团队的工作量,仅仅编写内容和发布是不够的,需要知道知识库对客户来说是否有用,需要了解客户获得的反馈,如果你正确的使用知识库软件&a…...
HiveSQL一天一个小技巧:如何将分组内数据填充完整?
0 需求1 需求分析需求分析:需求中需要求出分组中按成绩排名取倒数第二的值作为新字段,且分组内没有倒数第二条的时候取当前值。如果本题只是求分组内排序后倒数第二,则很简单,使用row_number()函数即可求出,但是本题问…...
【亲测可用】BEV Fusion (MIT) 环境配置
CUDA环境 首先我们需要打上对应版本的显卡驱动: 接下来下载CUDA包和CUDNN包: wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run sudo sh cuda_11.6.2_510.47.03_linux.runwget htt…...
日语AI面试高效通关秘籍:专业解读与青柚面试智能助攻
在如今就业市场竞争日益激烈的背景下,越来越多的求职者将目光投向了日本及中日双语岗位。但是,一场日语面试往往让许多人感到步履维艰。你是否也曾因为面试官抛出的“刁钻问题”而心生畏惧?面对生疏的日语交流环境,即便提前恶补了…...
Ubuntu系统下交叉编译openssl
一、参考资料 OpenSSL&&libcurl库的交叉编译 - hesetone - 博客园 二、准备工作 1. 编译环境 宿主机:Ubuntu 20.04.6 LTSHost:ARM32位交叉编译器:arm-linux-gnueabihf-gcc-11.1.0 2. 设置交叉编译工具链 在交叉编译之前&#x…...
基于服务器使用 apt 安装、配置 Nginx
🧾 一、查看可安装的 Nginx 版本 首先,你可以运行以下命令查看可用版本: apt-cache madison nginx-core输出示例: nginx-core | 1.18.0-6ubuntu14.6 | http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages ng…...
STM32标准库-DMA直接存储器存取
文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA(Direct Memory Access)直接存储器存取 DMA可以提供外设…...
ffmpeg(四):滤镜命令
FFmpeg 的滤镜命令是用于音视频处理中的强大工具,可以完成剪裁、缩放、加水印、调色、合成、旋转、模糊、叠加字幕等复杂的操作。其核心语法格式一般如下: ffmpeg -i input.mp4 -vf "滤镜参数" output.mp4或者带音频滤镜: ffmpeg…...
QT: `long long` 类型转换为 `QString` 2025.6.5
在 Qt 中,将 long long 类型转换为 QString 可以通过以下两种常用方法实现: 方法 1:使用 QString::number() 直接调用 QString 的静态方法 number(),将数值转换为字符串: long long value 1234567890123456789LL; …...
NXP S32K146 T-Box 携手 SD NAND(贴片式TF卡):驱动汽车智能革新的黄金组合
在汽车智能化的汹涌浪潮中,车辆不再仅仅是传统的交通工具,而是逐步演变为高度智能的移动终端。这一转变的核心支撑,来自于车内关键技术的深度融合与协同创新。车载远程信息处理盒(T-Box)方案:NXP S32K146 与…...
动态 Web 开发技术入门篇
一、HTTP 协议核心 1.1 HTTP 基础 协议全称 :HyperText Transfer Protocol(超文本传输协议) 默认端口 :HTTP 使用 80 端口,HTTPS 使用 443 端口。 请求方法 : GET :用于获取资源,…...
C# 表达式和运算符(求值顺序)
求值顺序 表达式可以由许多嵌套的子表达式构成。子表达式的求值顺序可以使表达式的最终值发生 变化。 例如,已知表达式3*52,依照子表达式的求值顺序,有两种可能的结果,如图9-3所示。 如果乘法先执行,结果是17。如果5…...
关于uniapp展示PDF的解决方案
在 UniApp 的 H5 环境中使用 pdf-vue3 组件可以实现完整的 PDF 预览功能。以下是详细实现步骤和注意事项: 一、安装依赖 安装 pdf-vue3 和 PDF.js 核心库: npm install pdf-vue3 pdfjs-dist二、基本使用示例 <template><view class"con…...
