MyBatis的CRUD
1. what
MyBatis是一款优秀的持久层框架,它支持自定义SQL、存储过程以及高级映射。MyBatis免除了几乎所有的JDBC代码以及设置参数和获取结果集的工作。MyBatis可以通过简单的XML或注解来配置和映射实体类型、接口、Java POJO(Plain Old Java Objects,普通老式Java对象)为数据库中的记录。
持久层:就是和数据库交互的一层——dao层,用于操作数据表记录的
框架:就是一个半成品,我们只需要引入该框架,加入自己的代码就可以完成相应的业务功能
持久层框架:MyBatis hirenate jpa等
ORM框架:Object Relative Mapping(对象关系映射)。表——实体类;一条记录——实体类的对象
表的字段——java实体类的属性
2. why
思考:JDBC操作数据库时代码量很大。
比如:查询时:需要手动给占位符赋值,需要手动把查询的结果封装到实体类中,需要手动关闭资源。
使用MyBatis可以帮你完成上面的操作。
3.快速搭建
1. 创建一个maven的java工程
File——New——New Project——Maven
Name : mybatis01
GroupId : com.zmq
2.引入MyBatis和mysql的依赖
<dependencies>
<!--mybatis的依赖--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.9</version></dependency>
<!--mysql的依赖--><dependency><groupId>repMaven.mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.33</version></dependency>
<!--lombok的依赖--><dependency><groupId>repMaven.org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.28</version></dependency>
<!--junit依赖--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency></dependencies>
引入的依赖有顺序,否则会报红,mybatis依赖需要在最前面
3.创建实体类,为了映射表中的记录
4.mybatis的配置文件——配置数据源信息
不需要背
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><environments default="development"><environment id="development"><transactionManager type="JDBC" /><dataSource type="POOLED"><!--name是固定的 value根据需要配置为自己的内容--><property name="driver" value="com.mysql.cj.jdbc.Driver" /><property name="url" value="jdbc:mysql://localhost:3306/zmq?serverTimezone=Asia/Shanghai" /><property name="username" value="root" /><property name="password" value="123456" /></dataSource></environment></environments>
</configuration>
- 修改为自己的数据库名称——
- 修改为自己的数据库用户名
- 修改为自己的数据库密码
5.mybatis的映射文件——编写自己的sql语句
在resources下创建mapper目录,在该目录下创建对应的映射文件——UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace:命名空间 -->
<mapper namespace="aaa"><!--select:用于编写查询的sql语句id:唯一标签 resultType:结果类型 sql执行完毕后返回对应的java实体类的类型 把查询的结果自动封装到该实体类的属性上--><select id="getById" resultType="com.zmq.entity.User">select * from user where id=#{id}</select>
</mapper>
6.将映射文件放入配置文件中
未来我们读取的只有配置文件
<!--引入映射文件-->
<mappers><mapper resource="mapper/UserMapper.xml"/>
</mappers>
7.测试mybatis是否正确
@Testpublic void test01() throws Exception{//1. 读取mybatis的配置文件InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");//2. 获取SqlSessionFactory对象---创建sqlSession的对象SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);//3. 获取SqlSession对象---表示java与数据库的一次连接SqlSession sqlSession=sessionFactory.openSession();//4. 执行sql语句//String statement, 执行映射文件中的哪个标签// Object parameter 需要的参数值User user= sqlSession.selectOne("aaa.getById",1);System.out.println(user);}
4. mybaits完成CRUD
4 .1 根据id查询
1.UserMapper.xml配置文件中写根据id查询的sql语句
<select id="getById" resultType="com.zmq.entity.User">select * from user where id=#{id}</select>
- select:用于编写查询的sql语句
- id:唯一标签
- resultType:结果类型 sql执行完毕后返回对应的java实体类的类型 把查询的结果自动封装到该实体类的属性上
- #{名称},相当于占位符
2.UserTest类中完成根据id查询的测试
//查询@Testpublic void test01() throws Exception{//1.读取mybatis的配置文件按InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");//2.获取SqlSessionFactory对象SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);//3.SqlSession sqlSession = sessionFactory.openSession();//4.User user = sqlSession.selectOne("UserMapper.getById",9);System.out.println(user);}
前三个步骤是固定的
首先:读取mybatis的配置文件,即mybatis.xml文件
获取SqlSessionFactory对象,创建sqlSession的对象
new SqlSessionFactoryBuilder().build(resourceAsStream)
- 获取SqlSession对象,表示java与数据库的一次连接
sessionFactory.openSession()
- 执行sql语句,有两个参数:
String statement, 执行映射文件中的哪个标签
Object parameter 需要的参数值
- 执行sql语句时,调用selectOne方法
4.2 添加
1.UserMapper.xml配置文件中写添加用户的sql语句
<!--增加--><insert id="add">insert into user values (null,#{u_name},#{password})</insert>
- insert:用于编写添加的sql语句
- #{名称},必须和实体类属性名一致
- 实体类中id为Integer类型,不然后续测试时会报错
- 不需要resultType
2.UserTest类中完成添加用户的测试
//添加@Testpublic void testAdd() throws Exception{//1.读取mybatis的配置文件按InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");//2.获取SqlSessionFactory对象——创建swssionFactory对象SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);//3.获取sqlSession对象——java与数据库的一次连接SqlSession sqlSession = sessionFactory.openSession();//4.创建一个user对象,传入添加用户的信息User user=new User(null,"汪芜","123456");//5.执行sql语句int row = sqlSession.insert("UserMapper.add", user);//将数据提交到数据库中sqlSession.commit();System.out.println(row);}
增删改与查询的不同点:
- 因为执行sql语句时,传入的是一个对象,而不能一次传递多个值,所以需要创建一个user对象,将要传递的值放入到user对象中,再在执行sql语句中传递符合要求的user对象
User user=new User(null,“汪芜”,“123456”);
int row = sqlSession.insert(“UserMapper.add”, user);
- 在执行完sql语句后,必须要提交到数据库中
sqlSession.commit();
- 执行时调用insert方法
4.3 修改
1.UserMapper.xml配置文件中写修改的sql语句
<!--修改--><update id="update">update user set u_name=#{name},password=#{password} where id=#{id}</update>
- update:用于编写修改的sql语句
- #{名称}:必须和实体类属性名一致
2.UserTest类中完成修改的测试
//修改@Testpublic void testUpdate() throws Exception {//1.读取mybatis的配置文件InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");//2.获取SqlSessionFactory对象---创建sqlSession的对象SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);//3.获取SqlSession对象---表示java与数据库的一次连接SqlSession sqlSession = sessionFactory.openSession();//4.创建一个user对象User user=new User(12,"lay","1007");//5.执行sql语句// String statement, 执行映射文件中的哪个标签// Object parameter 需要的参数值int row = sqlSession.update("UserMapper.update", user);//6.提交sqlSession.commit();System.out.println(row);}
- 和增加一样,需要创建一个user对象用来传递数据
- 执行时,调用update方法
- 执行完毕后,需要提交到数据库
4.4 删除
1.UserMapper.xml配置文件中写删除的sql语句
<!--删除--><delete id="del">delete from user where id=#{id}</delete>
2.UserTest类中完成删除的测试
//删除@Testpublic void testDel() throws Exception {//1.创建mybatis的配置文件InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");//2.创建SqlSessionFactory对象——创建sqlSession对象SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);//3.获取sqlSession对象——表示java与数据库的一次连接SqlSession sqlSession = sqlSessionFactory.openSession();//4.执行sql语句int row = sqlSession.delete("UserMapper.del", 30);sqlSession.commit();System.out.println(row);}
- 因为删除只需要传递一个id,所以不需要和增江、修改一样创建一个对象来传递值
- 同样,在执行完毕sql语句后,需要提交到数据库
5.企业开发模式
上面我们操作数据库表记录都是使用SqlSession类中的方法,而实际开发中我们习惯自己写方法,调用自己的方法传递相应的参数。但是这些方法没有方法体{},在接口中。而方法的实现交于mybatis框架完成
1.创建一个接口
public interface UserDao {//根据id查询用户信息public User queryById(int id);
}
2.映射文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace:命名空间必须和接口名一致
-->
<mapper namespace="com.zmq.dao.UserDao"><!--select:用于编写查询的sql语句id:唯一标签,必须和Dao接口中的方法名一致resultType:结果类型 sql执行完毕后返回对应的java实体类的类型 把查询的结果自动封装到该实体类的属性上--><select id="getById" resultType="com.zmq.entity.User">select * from user where id=#{id}</select>
</mapper>
3.测试
public class UserTest {//根据id查询@Testpublic void testGetById() throws IOException {//1.获取mybatis的配置文件InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");//2.获取SqlSessionFactory对象——创建sqlSessionFactory对象SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);//3.获取sqlSession对象SqlSession sqlSession = sqlSessionFactory.openSession();//4.获取dao接口的代理实现类UserDao userDao=sqlSession.getMapper(UserDao.class);//5.调用自己类中的方法User user = userDao.getById(12);System.out.println(user.getU_name());}
}
4.补充@Before注解
@Before注解:是Junit中的一个注解,它用于标记一个方法,在每个测试方法执行之前都会被自动调用。 通过使用@Before注解,我们可以将一些通用的准备操作(如创建对象、初始化变量等)放置在一个方法中,以避免在每个测试方法中重复编写相同的准备代码。
@Before注解可以将测试中的一些固定步骤提取出来
UserDao userDao=null;
SqlSession sqlSession=null;
@Before
public void before() throws Exception{//1.获取mybatis的配置文件InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");//2.获取SqlSessionFactory对象——创建sqlSessionFactory对象SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);//3.获取sqlSession对象sqlSession = sqlSessionFactory.openSession();//4.获取dao接口的代理实现类userDao=sqlSession.getMapper(UserDao.class);
}
6.企业模式完成CRUD
6.0 前期准备
1.引入依赖
创建好一个mybatis的java工程后,需要在pom.xml文件中引入相关依赖
<dependencies>
<!--mybatis的依赖--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.9</version></dependency>
<!--mysql的依赖--><dependency><groupId>repMaven.mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.33</version></dependency>
<!--lombok的依赖--><dependency><groupId>repMaven.org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.28</version></dependency>
<!--junit依赖--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><!--打印日志--><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>5.3.2</version></dependency>
</dependencies>
2.在resources下创建配置文件——mybatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><environments default="development"><environment id="development"><transactionManager type="JDBC" /><dataSource type="POOLED"><!--name是固定的 value根据需要配置为自己的内容--><property name="driver" value="com.mysql.cj.jdbc.Driver" /><property name="url" value="jdbc:mysql://localhost:3306/zmq?serverTimezone=Asia/Shanghai" /><property name="username" value="root" /><property name="password" value="123456" /></dataSource></environment></environments>
</configuration>
3.创建相应的实体类——entity——Student
package com.zmq.entity;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;/*** @program: mybatis01work* @description: 学生表* @author: 赵梦倩* @create: 2024-05-20 16:42**/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {private Integer id;private String name;private String phone;private String email;private String profession;private Integer age;
}
4.创建相应的接口——dao——StudentDao
package com.zmq.dao;import com.zmq.entity.Student;import java.util.List;/*** @program: mybatis01work* @description: 学生表的相关方法接口* @author: 赵梦倩* @create: 2024-05-20 16:44**/
public interface StudentDao {//1.根据id查询public Student getById(int id);//2.查询所有public List<Student> getAll();//添加public int add(Student student);//修改public int update(Student student);//删除public int delete(int id);}
5.创建mybatis的映射文件——mapper——StudentMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace:命名空间 -->
<mapper namespace="com.zmq.dao.StudentDao"></mapper>
6.在配置文件中引入映射文件
<!--引入映射文件--><mappers><mapper resource="mapper/StudentMapper.xml"/></mappers>
6.1 查询所有
1.映射文件【StudentMapper.xml】中写sql语句
<select id="getAll" resultType="com.zmq.entity.Student">select * from t_student</select>
2.单元测试类中测试方法
@Testpublic void testGetAll() throws IOException {InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);SqlSession sqlSession = sqlSessionFactory.openSession();StudentDao studentDao=sqlSession.getMapper(StudentDao.class);List<Student> all = studentDao.getAll();for (Student s:all) {System.out.println(s.getName());}}
6.2 根据id查询
1.映射文件【StudentMapper.xml】中写sql语句
<select id="getById" resultType="com.zmq.entity.Student">select * from t_student where id=#{id}</select>
2.单元测试类中测试方法
@Testpublic void testGetById() throws IOException {InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);SqlSession sqlSession = sqlSessionFactory.openSession();StudentDao studentDao=sqlSession.getMapper(StudentDao.class);Student byId = studentDao.getById(2);System.out.println(byId.getName());}
6.3 添加
1.映射文件【StudentMapper.xml】中写sql语句
<insert id="add" >insert into t_student values (null,#{name},#{phone},#{email},#{profession},#{age})</insert>
2.单元测试类中测试方法
@Testpublic void testAdd() throws IOException {InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);SqlSession sqlSession = sqlSessionFactory.openSession();StudentDao studentDao=sqlSession.getMapper(StudentDao.class);Student student=new Student(null,"张数","1007","110qq.com","软件工程",16);int add = studentDao.add(student);System.out.println(add);sqlSession.commit();}
6.4 修改
1.映射文件【StudentMapper.xml】中写sql语句
<update id="update">update t_student set name=#{name},phone=#{phone},email=#{email},profession=#{profession},age=#{age} where id=#{id}</update>
2.单元测试类中测试方法
@Testpublic void testUpdate() throws IOException {InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);SqlSession sqlSession = sqlSessionFactory.openSession();StudentDao studentDao=sqlSession.getMapper(StudentDao.class);Student student=new Student(25,"张数三","1007","110qq.com","软件工程",16);int update = studentDao.update(student);System.out.println(update);sqlSession.commit();}
6.5 删除
1.映射文件【StudentMapper.xml】中写sql语句
<delete id="delete">delete from t_student where id=#{id}
</delete>
2.单元测试类中测试方法
@Testpublic void testDel() throws IOException {InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);SqlSession sqlSession = sqlSessionFactory.openSession();StudentDao studentDao=sqlSession.getMapper(StudentDao.class);int delete = studentDao.delete(25);System.out.println(delete);sqlSession.commit();}
7. idea安装的相关插件
插件1:MyBatisX
可以用于纠错
插件2:Lombok
帮忙生成set,get,toString,构造方法——通过注解
- 引入lombok依赖
<!--lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.24</version></dependency>
- 实体类中使用lombok注解
//set和get以toString方法生成
@Data
//无参构造方法
@NoArgsConstructor
//有参构造方法
@AllArgsConstructor
8.易错点
8.1 导包时
两个xml文件要打开记事本粘贴
否则会报错——创建实例错误
8.2 获取结果name为空
因为创建实体类时属性与数据库表属性不一致导致
解决:实体类属性与数据库表属性完全一致
8.3 Mapped Statements collection does not contain
两种可能:
①写错名称
②配置文件中没有引入映射文件
其他错误:
①密码账号错误
②写错sql语句——在数据库中执行下
相关文章:
MyBatis的CRUD
1. what MyBatis是一款优秀的持久层框架,它支持自定义SQL、存储过程以及高级映射。MyBatis免除了几乎所有的JDBC代码以及设置参数和获取结果集的工作。MyBatis可以通过简单的XML或注解来配置和映射实体类型、接口、Java POJO(Plain Old Java Objects,普…...
leetcode 题目解析 第3题 无重复字符的最长子串
给定一个字符串 s ,请你找出其中不含有重复字符的 最长 子串的长度。 示例 1: 输入: s “abcabcbb” 输出: 3 解释: 因为无重复字符的最长子串是 “abc”,所以其长度为 3。 示例 2: 输入: s “bbbbb” 输出: 1 解释: 因为无重复字符的最长子串是 “b”…...
深度学习入门--神经网络
初学,若有错误,恳请指正。 目录 初学,若有错误,恳请指正。 3.1 从感知机到神经网络 3.1.1 神经网络的例子 3.1.2 复习感知机 3.1.3 激活函数登场 3.2 激活函数 3.2.1 sigmoid 函数 3.2.2 阶跃函数的实现 3.2.3 阶跃函数…...
pycharm 调试 debug 进入 remote_sources
解决办法1: pycharm函数跳转到remote_sources中的文件中_pycharm修改remotesource包存放地址-CSDN博客 file->settings->project structure将项目文件夹设为"Sources"(此时文件夹会变为蓝色)。 解决方法2 Debug:使用Pychar…...
【复习】计算机网络
网络模型 OSI 应用层:给应用程序提供统一的接口表示层:把数据转换成兼容另一个系统能识别的格式会话层:负责建立、管理、终止表示层实体之间的通信会话传输层:负责端到端的数据传输网络层:负责数据的路由、转发、分片…...
CentOS停服后的替代选择:openEuler、Rocky Linux及其他系统的未来展望
CentOS停服后的替代选择:openEuler、Rocky Linux及其他系统的未来展望 引言CentOS停服的背景华为openEuler:面向未来的开源操作系统1. 简介2. 特点3. 发展趋势 Rocky Linux:CentOS的精神继承者1. 简介2. 特点3. 发展趋势 其他可选的替代系统1…...
ollama+open-webui,本地部署自己的大模型
目录 一、效果预览 二、部署ollama 1.ollama说明 2.安装流程 2.1 windows系统 2.1.1下载安装包 2.1.2验证安装结果 2.1.3设置模型文件保存地址 2.1.4拉取大模型镜像 2.2linux系统 2.2.1下载并安装ollama 2.2.2设置环境变量 2.2.3拉取模型文件 三、部署open-webui…...
Oracle EBS 12.1和APEX 集成时 Apache的配置代理
在有些场景下,apex的前端服务不是和oracle EBS 应用部署在同一个服务器上或者要求apex和访问地址和EBS公用同一个域名同一个端口,那么怎么才能做到用EBS 的域名和端口来实现对apex的访问呢 通过配置代理规则解决,以Oracle EBS 12.1.3 为例&am…...
hive开窗函数边界值ROWS BETWEEN 和 RANGE BETWEEN区别
目录 一、概念 1.rows between ... and ... 2.range between ... and ... 二、语法 1.关键词含义 一、概念 1.rows between ... and ... rows:指以行号来决定frame的范围,是物理意义上的行。 2.range between ... and ... range:指以当…...
HTML第一节
一.HTML标签 注意:1.双标签是要包裹内容的 (单标签单独记) 二.HTML骨架 1.骨架规则 注意:1.title为网页的名字 2.VS code自动生成骨架 注意:1.先输入感叹号(必须为英文) 再按回车 三.标签间的…...
Google第三方库详解------ProtoBuf详解 + 样例(5万字详解!)
目录 前言: 提示: 插件 入门: ProtoBuf普通字段类型: 编译命令: 序列化与反序列化: Proto3语法: 字段规则:数组类型 应用 将通讯录数据序列化后写入文件 工具介绍&#x…...
机器学习数学通关指南——泰勒公式
前言 本文隶属于专栏《机器学习数学通关指南》,该专栏为笔者原创,引用请注明来源,不足和错误之处请在评论区帮忙指出,谢谢! 本专栏目录结构和参考文献请见《机器学习数学通关指南》 正文 一句话总结 泰勒公式是用多…...
如果后台的Long类型的数据返回是null,那么Android客户端的数据bean的kotlin的Long类型的字段接受到数据后是null空指针吗?
如果后台的Long类型的数据返回是null,那么Android客户端的数据bean的kotlin的Long类型的字段接受到数据后是null空指针吗? DeepSeek R1 思考 35 秒 思考过程 好的,用户的问题是关于在Android客户端使用Kotlin处理后台返回的Long类型数据为n…...
ai-financial-agent - 为金融投资打造的AI代理
探索人工智能在投资研究中的应用。本项目仅用于**教育**目的,不用于真实交易或投资。 作者声明: 本项目仅用于教育和研究目的。 不用于真实交易或投资不提供任何保证或担保过去的表现并不代表未来的结果Creator 对经济损失不承担任何责任咨询财务顾问…...
学习路程三 数据加载及向量化
前序 之前简单粗暴将LangChain分了几块,现在就挨着了解学习每块内容。今天主要从文档这条路来看。 本地文档这一条链路,通过加载,分割,向量化,再存储数据库 ps:看到这里还想继续实操下去,可以…...
基于GWO灰狼优化的WSN网络最优节点部署算法matlab仿真
目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.本算法原理 5.完整程序 1.程序功能描述 无线传感器网络(Wireless Sensor Network, WSN)由大量分布式传感器节点组成,用于监测物理或环境状况。节点部署是 WSN 的关键问…...
保姆级! 本地部署DeepSeek-R1大模型 安装Ollama Api 后,Postman本地调用 deepseek
要在Postman中访问Ollama API并调用DeepSeek模型,你需要遵循以下步骤。首先,确保你有一个有效的Ollama服务器实例运行中,并且DeepSeek模型已经被加载。 可以参考我的这篇博客 保姆级!使用Ollama本地部署DeepSeek-R1大模型 并java…...
架构对比分析
您提到的两种架构描述本质上遵循相同的分层设计理念,但存在差异的原因在于 视角不同 和 硬件平台特性。以下是详细解析: 一、架构对比分析 1. 逻辑分层(通用软件设计视角) 应用层(UI/用户交互)↓ 业务逻辑…...
【每日八股】Redis篇(二):数据结构
Redis 数据类型? 主要有 STRING、LIST、ZSET、SET 和 HASH。 STRING String 类型底层的数据结构实现主要是 SDS(简单动态字符串),其主要应用场景包括: 缓存对象:可以用 STRING 缓存整个对象的 JSON&…...
windows使用命令解压jar包,替换里面的文件。并重新打包成jar包,解决Failed to get nested archive for entry
有一个jar包,需要替换里面的文件,使用解压工具打开项目,然后找到对应的子包,再次打开,然后进行手工替换重新压缩成jar包后,发现启动服务报错Failed to get nested archive for entry。 使用下面的命令可实…...
地震勘探——干扰波识别、井中地震时距曲线特点
目录 干扰波识别反射波地震勘探的干扰波 井中地震时距曲线特点 干扰波识别 有效波:可以用来解决所提出的地质任务的波;干扰波:所有妨碍辨认、追踪有效波的其他波。 地震勘探中,有效波和干扰波是相对的。例如,在反射波…...
《Qt C++ 与 OpenCV:解锁视频播放程序设计的奥秘》
引言:探索视频播放程序设计之旅 在当今数字化时代,多媒体应用已渗透到我们生活的方方面面,从日常的视频娱乐到专业的视频监控、视频会议系统,视频播放程序作为多媒体应用的核心组成部分,扮演着至关重要的角色。无论是在个人电脑、移动设备还是智能电视等平台上,用户都期望…...
边缘计算医疗风险自查APP开发方案
核心目标:在便携设备(智能手表/家用检测仪)部署轻量化疾病预测模型,实现低延迟、隐私安全的实时健康风险评估。 一、技术架构设计 #mermaid-svg-iuNaeeLK2YoFKfao {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg…...
centos 7 部署awstats 网站访问检测
一、基础环境准备(两种安装方式都要做) bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats࿰…...
Java多线程实现之Callable接口深度解析
Java多线程实现之Callable接口深度解析 一、Callable接口概述1.1 接口定义1.2 与Runnable接口的对比1.3 Future接口与FutureTask类 二、Callable接口的基本使用方法2.1 传统方式实现Callable接口2.2 使用Lambda表达式简化Callable实现2.3 使用FutureTask类执行Callable任务 三、…...
ServerTrust 并非唯一
NSURLAuthenticationMethodServerTrust 只是 authenticationMethod 的冰山一角 要理解 NSURLAuthenticationMethodServerTrust, 首先要明白它只是 authenticationMethod 的选项之一, 并非唯一 1 先厘清概念 点说明authenticationMethodURLAuthenticationChallenge.protectionS…...
C# 类和继承(抽象类)
抽象类 抽象类是指设计为被继承的类。抽象类只能被用作其他类的基类。 不能创建抽象类的实例。抽象类使用abstract修饰符声明。 抽象类可以包含抽象成员或普通的非抽象成员。抽象类的成员可以是抽象成员和普通带 实现的成员的任意组合。抽象类自己可以派生自另一个抽象类。例…...
【服务器压力测试】本地PC电脑作为服务器运行时出现卡顿和资源紧张(Windows/Linux)
要让本地PC电脑作为服务器运行时出现卡顿和资源紧张的情况,可以通过以下几种方式模拟或触发: 1. 增加CPU负载 运行大量计算密集型任务,例如: 使用多线程循环执行复杂计算(如数学运算、加密解密等)。运行图…...
Rust 异步编程
Rust 异步编程 引言 Rust 是一种系统编程语言,以其高性能、安全性以及零成本抽象而著称。在多核处理器成为主流的今天,异步编程成为了一种提高应用性能、优化资源利用的有效手段。本文将深入探讨 Rust 异步编程的核心概念、常用库以及最佳实践。 异步编程基础 什么是异步…...
Python ROS2【机器人中间件框架】 简介
销量过万TEEIS德国护膝夏天用薄款 优惠券冠生园 百花蜂蜜428g 挤压瓶纯蜂蜜巨奇严选 鞋子除臭剂360ml 多芬身体磨砂膏280g健70%-75%酒精消毒棉片湿巾1418cm 80片/袋3袋大包清洁食品用消毒 优惠券AIMORNY52朵红玫瑰永生香皂花同城配送非鲜花七夕情人节生日礼物送女友 热卖妙洁棉…...
