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

MybatisPlus - 核心功能

文章目录

      • 1.MybatisPlus实现基本的CRUD
        • 快速开始
        • 常见注解
        • 常见配置
      • 2.使用条件构建造器构建查询和更新语句
        • 条件构造器
        • 自定义SQL
        • Service接口

在这里插入图片描述

官网
MybatisPlus无侵入和方便快捷.
MybatisPlus不仅仅可以简化单表操作,而且还对Mybatis的功能有很多的增强。可以让我们的开发更加的简单,高效。
通过今天的学习,我们要达成下面的目标:

  • 能利用MybatisPlus实现基本的CRUD
  • 会使用条件构建造器构建查询和更新语句

1.MybatisPlus实现基本的CRUD

快速开始

初始化工程: 配置文件

spring:datasource:url: jdbc:mysql://127.0.0.1:3306/mp?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghaidriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: root
logging:level:com.itheima: debugpattern:dateformat: HH:mm:ss
mybatis:mapper-locations: classpath*:mapper/*.xml

实体类

@Data
public class User {/*** 用户id*/private Long id;/*** 用户名*/private String username;/*** 密码*/private String password;/*** 注册手机号*/private String phone;/*** 详细信息*/private String info;/*** 使用状态(1正常 2冻结)*/private Integer status;/*** 账户余额*/private Integer balance;/*** 创建时间*/private LocalDateTime createTime;/*** 更新时间*/private LocalDateTime updateTime;
}

dao层/mapper层

public interface UserMapper{void saveUser(User user);void deleteUser(Long id);void updateUser(User user);User queryUserById(@Param("id") Long id);List<User> queryUserByIds(@Param("ids") List<Long> ids);
}

mapper.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">
<mapper namespace="com.itheima.mp.mapper.UserMapper"><insert id="saveUser" parameterType="com.itheima.mp.domain.po.User">INSERT INTO `user` (`id`, `username`, `password`, `phone`, `info`, `balance`)VALUES(#{id}, #{username}, #{password}, #{phone}, #{info}, #{balance});</insert><update id="updateUser" parameterType="com.itheima.mp.domain.po.User">UPDATE `user`<set><if test="username != null">`username`=#{username}</if><if test="password != null">`password`=#{password}</if><if test="phone != null">`phone`=#{phone}</if><if test="info != null">`info`=#{info}</if><if test="status != null">`status`=#{status}</if><if test="balance != null">`balance`=#{balance}</if></set>WHERE `id`=#{id};</update><delete id="deleteUser" parameterType="com.itheima.mp.domain.po.User">DELETE FROM user WHERE id = #{id}</delete><select id="queryUserById" resultType="com.itheima.mp.domain.po.User">SELECT *FROM userWHERE id = #{id}</select><select id="queryUserByIds" resultType="com.itheima.mp.domain.po.User">SELECT *FROM user<if test="ids != null">WHERE id IN<foreach collection="ids" open="(" close=")" item="id" separator=",">#{id}</foreach></if>LIMIT 10</select></mapper>

现在我们来改造!用mp快速体验一下:

<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.1</version></dependency>

在这里插入图片描述

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.mp.domain.po.User;
import org.apache.ibatis.annotations.Param;import java.util.List;public interface UserMapper extends BaseMapper<User> {
}

把那些方法全部都删除了,然后把mapper.xml文件也一并删除.我们继承的这个"爸爸"里面这些方法它都有,所以我们直接去测试类测试即可.

import com.itheima.mp.domain.po.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.time.LocalDateTime;
import java.util.List;@SpringBootTest
class UserMapperTest {@Autowiredprivate UserMapper userMapper;@Testvoid testInsert() {User user = new User();user.setId(5L);user.setUsername("Lucy");user.setPassword("123");user.setPhone("18688990011");user.setBalance(200);user.setInfo("{\"age\": 24, \"intro\": \"英文老师\", \"gender\": \"female\"}");user.setCreateTime(LocalDateTime.now());user.setUpdateTime(LocalDateTime.now());userMapper.insert(user);}@Testvoid testSelectById() {User user = userMapper.selectById(5L);System.out.println("user = " + user);}@Testvoid testQueryByIds() {List<User> users = userMapper.selectBatchIds(List.of(1L, 2L, 3L, 4L));users.forEach(System.out::println);}@Testvoid testUpdateById() {User user = new User();user.setId(5L);user.setBalance(20000);userMapper.updateById(user);}@Testvoid testDeleteUser() {userMapper.deleteById(5L);}
}

全部都能测试成功,而且updateById语句如果你没有修改其他的字段那么其他字段不会修改.这样实现单表增删改查全部搞定.

常见注解

MybatisPlus通过扫描实体类,并基于反射获取实体类信息作为数据库表信息.
在这里插入图片描述
在这里插入图片描述

@Data
@TableName("user")
public class User {/*** 用户id*/@TableId(type = IdType.AUTO)//默认使用雪花算法生成idprivate Long id;/*** 用户名*/
//    @TableField("`username`")private String username;/*** 密码*/
//    @TableField(exist = false)private String password;/*** 注册手机号*/private String phone;/*** 详细信息*/private String info;/*** 使用状态(1正常 2冻结)*/private Integer status;/*** 账户余额*/private Integer balance;/*** 创建时间*/private LocalDateTime createTime;/*** 更新时间*/private LocalDateTime updateTime;
}
常见配置

在这里插入图片描述

但是其实大部分都是默认配置具体可以看官网那些是默认配置

在这里插入图片描述

mybatis-plus:type-aliases-package: com.itheima.mp.domain.poglobal-config:db-config:id-type: auto

2.使用条件构建造器构建查询和更新语句

核心功能:

条件构造器

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  @Testvoid testQueryWrapper(){Wrapper<User> wrapper = new QueryWrapper<User>().select("id", "username", "info","balance").like("username", "o").ge("balance", 1000);List<User> users = userMapper.selectList(wrapper);users.forEach(System.out::println);}

debug信息:

14:40:41 DEBUG 26264 — [ main] c.i.mp.mapper.UserMapper.selectList : ==> Preparing: SELECT id,username,info,balance FROM user WHERE (username LIKE ? AND balance >= ?)
14:40:41 DEBUG 26264 — [ main] c.i.mp.mapper.UserMapper.selectList : > Parameters: %o%(String), 1000(Integer)
14:40:41 DEBUG 26264 — [ main] c.i.mp.mapper.UserMapper.selectList : <
Total: 1

  @Testvoid testUpdateWrapper(){//1.要更新的数据User user = new User();user.setBalance(2000);//2.更新的条件QueryWrapper<User> wrapper = new QueryWrapper<User>().eq("username", "jack");//3.执行更新userMapper.update(user,wrapper);}

debug日志信息:

14:45:32 DEBUG 15964 — [ main] com.itheima.mp.mapper.UserMapper.update : ==> Preparing: UPDATE user SET balance=? WHERE (username = ?)
14:45:32 DEBUG 15964 — [ main] com.itheima.mp.mapper.UserMapper.update : > Parameters: 2000(Integer), jack(String)
14:45:32 DEBUG 15964 — [ main] com.itheima.mp.mapper.UserMapper.update : <
Updates: 1

在这里插入图片描述

@Testvoid testUpdateWrapper(){UpdateWrapper<User> wrapper = new UpdateWrapper<User>().setSql("balance = balance + 200").in("id", List.of(1L, 2L, 3L, 4L));userMapper.update(null,wrapper);}

在这里插入图片描述
但是这种写法是硬编码.
推荐Lambda

 @Testvoid testLambdaQueryWrapper(){LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>().select(User::getId, User::getUsername,User::getInfo, User::getBalance).like(User::getUsername, "o").ge(User::getBalance, 1000);List<User> users = userMapper.selectList(wrapper);users.forEach(System.out::println);}

在这里插入图片描述

自定义SQL

我们可以利用MybatisPlus的wrapper来构建where条件,然后自己定义SQL语句中剩下部分.
在这里插入图片描述
这样确实方便但是这是在业务层中,这在很多企业中是不允许的.
在这里插入图片描述
在这里插入图片描述

@Testvoid testCustomSql(){List<Long>ids = List.of(1L, 2L, 3L, 4L);int amount = 200;QueryWrapper<User> wrapper = new QueryWrapper<User>().in("id", ids);userMapper.updateBalanceByIds(wrapper, amount);}
public interface UserMapper extends BaseMapper<User> {@Update("UPDATE user set balance = balance + #{amount} ${ew.customSqlSegment}")void updateBalanceByIds(@Param(Constants.WRAPPER) QueryWrapper<User> wrapper, @Param("amount") int amount);
}
Service接口

在这里插入图片描述
在这里插入图片描述

@SpringBootTest
class IUserServiceTest {@Autowiredprivate IUserService userService;@Testvoid testSave(){User user = new User();
//        user.setId(5L);user.setUsername("yyy");user.setPassword("123");user.setPhone("18688990011");user.setBalance(200);user.setInfo("{\"age\": 24, \"intro\": \"英文老师\", \"gender\": \"female\"}");user.setCreateTime(LocalDateTime.now());user.setUpdateTime(LocalDateTime.now());userService.save(user);}@Testvoid testQuery(){List<User> users = userService.listByIds(List.of(1L, 2L, 3L));users.forEach(System.out::println);}}

我们发现Iservice 和 baseMapper其实有很多方法都是重复的,从功能上是一致的,那我们应该如何选择?这里给出一个案例来进行讲解:
在这里插入图片描述

<!--swagger-->
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-openapi2-spring-boot-starter</artifactId><version>4.1.0</version>
</dependency>
<!--web-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>

然后配置swagger信息

knife4j:enable: trueopenapi:title: 用户管理接口文档description: "用户管理接口文档"email: zhanghuyi@itcast.cnconcat: 虎哥url: https://www.itcast.cnversion: v1.0.0group:default:group-name: defaultapi-rule: packageapi-rule-resources:- com.itheima.mp.controller
@Data
@ApiModel(description = "用户表单实体")
public class UserFormDTO {@ApiModelProperty("id")private Long id;@ApiModelProperty("用户名")private String username;@ApiModelProperty("密码")private String password;@ApiModelProperty("注册手机号")private String phone;@ApiModelProperty("详细信息,JSON风格")private String info;@ApiModelProperty("账户余额")private Integer balance;
}
@Data
@ApiModel(description = "用户VO实体")
public class UserVO {@ApiModelProperty("用户id")private Long id;@ApiModelProperty("用户名")private String username;@ApiModelProperty("详细信息")private String info;@ApiModelProperty("使用状态(1正常 2冻结)")private Integer status;@ApiModelProperty("账户余额")private Integer balance;
}

@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {private final IUserService userService;// 注入userService 有final才注入//    public UserController(IUserService userService) {
//        this.userService = userService;
//    }@ApiOperation("新增用户接口")@PostMappingpublic void saveUser(@RequestBody UserFormDTO userDTO){//1.DTO拷贝1到POUser user = BeanUtil.copyProperties(userDTO, User.class);//2.新增userService.save(user);}@ApiOperation("删除用户接口")@DeleteMapping("/{id}")public void DeleteUser(@ApiParam(name = "id", value = "用户id", required = true) @PathVariable("id") Long id){userService.removeById(id);}@ApiOperation("根据id查询用户接口")@GetMapping("/{id}")public UserVO queryUser(@ApiParam(name = "id", value = "用户id", required = true) @PathVariable("id") Long id){User user = userService.getById(id);UserVO userVO = BeanUtil.copyProperties(user, UserVO.class);return userVO;}@ApiOperation("根据id批量查询用户接口")@PostMappingpublic List<UserVO> queryUser(@RequestParam("ids") List<Long> ids){List<User> users = userService.listByIds(ids);return BeanUtil.copyToList(users, UserVO.class);}}

以后在大多数场景下直接用IService就可以了,因为这几个没有业务逻辑。
第五个接口是有业务的接口,要判断状态,判断余额数量等等。。
在controller中

@ApiOperation("扣减用户余额接口")@PutMapping("/{id}/deduction/{money}")public void deduction(@ApiParam(name = "id", value = "用户id", required = true) @PathVariable("id") Long id,@ApiParam(name = "money", value = "扣减金额", required = true) @PathVariable("money") Integer money) {userService.deduction(id, money);}

service层

public interface IUserService extends IService<User> {void deduction(Long id, Integer money);
}

serviceImpl

@Service
public class UserServiceImlp extends ServiceImpl<UserMapper, User> implements IUserService  {@Overridepublic void deduction(Long id, Integer money) {//1. 根据id查询用户User user = this.getById(id);//2.检验用户状态if(user==null || user.getStatus()!=1){throw new RuntimeException("用户状态异常");}//3.检验余额是否充足if(user.getBalance()<money){throw new RuntimeException("余额不足");}//4.扣除余额baseMapper.deductBalance(id,money);}
}

mapper:

public interface UserMapper extends BaseMapper<User> {@Update("UPDATE user set balance = balance + #{amount} ${ew.customSqlSegment}")void updateBalanceByIds(@Param(Constants.WRAPPER) QueryWrapper<User> wrapper, @Param("amount") int amount);@Update("UPDATE user set balance = balance - #{money} WHERE id = #{id}")void deductBalance(@Param("id") Long id,@Param("money") Integer money);
}
import cn.hutool.core.bean.BeanUtil;
import com.itheima.mp.domain.dto.UserFormDTO;
import com.itheima.mp.domain.po.User;
import com.itheima.mp.domain.vo.UserVO;
import com.itheima.mp.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;import java.util.List;@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {private final IUserService userService;// 注入userService 有final才注入//    public UserController(IUserService userService) {
//        this.userService = userService;
//    }@ApiOperation("新增用户接口")@PostMappingpublic void saveUser(@RequestBody UserFormDTO userDTO){//1.DTO拷贝1到POUser user = BeanUtil.copyProperties(userDTO, User.class);//2.新增userService.save(user);}@ApiOperation("删除用户接口")@DeleteMapping("/{id}")public void DeleteUser(@ApiParam(name = "id", value = "用户id", required = true) @PathVariable("id") Long id){userService.removeById(id);}@ApiOperation("根据id查询用户接口")@GetMapping("/{id}")public UserVO queryUser(@ApiParam(name = "id", value = "用户id", required = true) @PathVariable("id") Long id){User user = userService.getById(id);UserVO userVO = BeanUtil.copyProperties(user, UserVO.class);return userVO;}@ApiOperation("根据id批量查询用户接口")@PostMappingpublic List<UserVO> queryUser(@RequestParam("ids") List<Long> ids){List<User> users = userService.listByIds(ids);return BeanUtil.copyToList(users, UserVO.class);}@ApiOperation("扣减用户余额接口")@PutMapping("/{id}/deduction/{money}")public void deduction(@ApiParam(name = "id", value = "用户id", required = true) @PathVariable("id") Long id,@ApiParam(name = "money", value = "扣减金额", required = true) @PathVariable("money") Integer money) {userService.deduction(id, money);}}

在这里插入图片描述
query:

@Data
@ApiModel(description = "用户查询条件实体")
public class UserQuery {@ApiModelProperty("用户名关键字")private String name;@ApiModelProperty("用户状态:1-正常,2-冻结")private Integer status;@ApiModelProperty("余额最小值")private Integer minBalance;@ApiModelProperty("余额最大值")private Integer maxBalance;
}

controller:

@ApiOperation("根据复杂条件查询用户接口")@GetMapping("/list")public List<UserVO> queryUserByCondition(UserQuery query){List<User>users = userService.queryUsers(query.getName(),query.getStatus(),query.getMinBalance(),query.getMaxBalance())return BeanUtil.copyToList(users, UserVO.class);}

IUservice:

public interface IUserService extends IService<User> {void deduction(Long id, Integer money);List<User> queryUsers(String name, Integer status, Integer minBalance, Integer maxBalance);
}

serviceimpl

public List<User> queryUsers(String name, Integer status, Integer minBalance, Integer maxBalance) {return  lambdaQuery().like(name != null, User::getUsername, name).eq(status != null, User::getStatus, status).ge(minBalance != null, User::getBalance, minBalance).le(name != null, User::getBalance, maxBalance).list();}

在这里插入图片描述

@Service
public class UserServiceImlp extends ServiceImpl<UserMapper, User> implements IUserService  {@Transactionalpublic void deduction(Long id, Integer money) {//1. 根据id查询用户User user = this.getById(id);//2.检验用户状态if(user==null || user.getStatus()!=1){throw new RuntimeException("用户状态异常");}//3.检验余额是否充足if(user.getBalance()<money){throw new RuntimeException("余额不足");}//4.扣除余额
//        baseMapper.deductBalance(id,money);int remainBalance = user.getBalance()-money;//乐观锁 compare and setlambdaUpdate().set(User::getBalance,remainBalance).set(remainBalance==0,User::getStatus,2).eq(User::getId,id).eq(User::getBalance,user.getBalance()) //乐观锁 让并发安全性更好.update();//不要忘记这一条}
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
上面哪一种一条条执行,每一次提交都是一次网络请求,每次网络请求都要耗费一定的时间,而下面每次插入1000条,采取预编译方案,相当于每1000次才发一次网络请求
在这里插入图片描述
如何把我们的sql语句变成这样?用动态SQL,foreach,或者还是使用mp的批处理指令,但是你会发现这个sql语句不对啊,但其实这个不对只是缺少了一个参数rewriteBatchedStatements=true参数,这个配置是mysql的配置,默认为false所以我们之前以为的批处理实际上都是一条条的插入,所以我们要改这个配置

spring:datasource:url: jdbc:mysql://127.0.0.1:3306/mp?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=truedriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: root

在url后面加上这个参数即可

在这里插入图片描述
在这里插入图片描述

相关文章:

MybatisPlus - 核心功能

文章目录 1.MybatisPlus实现基本的CRUD快速开始常见注解常见配置 2.使用条件构建造器构建查询和更新语句条件构造器自定义SQLService接口 官网 MybatisPlus无侵入和方便快捷. MybatisPlus不仅仅可以简化单表操作&#xff0c;而且还对Mybatis的功能有很多的增强。可以让我们的开…...

小柴冲刺软考中级嵌入式系统设计师系列二、嵌入式系统硬件基础知识(6)嵌入式系统总线及通信接口

目录 越努力&#xff0c;越幸运&#xff01; flechazo 小柴冲刺软考中级嵌入式系统设计师系列总目录 一、PCI、PCI-E 等接口基本原理与结构 1、PCI (1)高速性。 (2)即插即用性。 (3)可靠性。 (4)复杂性。 (5)自动配置。 (6)共享中断。 (7)扩展性好。 (8)多路复用。…...

利用字典对归一化后的数据0误差还原

假设我对精度要求很高&#xff0c;高到无法容忍有任何误差&#xff0c;那么我先将x按照大小排序&#xff0c;然后归一化&#xff0c;用字典将归一化前后的x存储下来&#xff0c;在深度学习时使用归一化后的x进行处理&#xff0c;但是最后画图等处理时&#xff0c;我用字典取出归…...

HarmonyOS:UIAbility组件概述

一、概述 UIAbility组件是一种包含UI的应用组件&#xff0c;主要用于和用户交互。 UIAbility的设计理念&#xff1a; 原生支持应用组件级的跨端迁移和多端协同。支持多设备和多窗口形态。 UIAbility划分原则与建议&#xff1a; UIAbility组件是系统调度的基本单元&#xff0c…...

12寸半导体厂说的华夫区是什么意思

1\什么是华夫板 在半导体行业中,“华夫区”通常指的是“华夫板”(Waffle Slab),这是一种特殊设计的楼板,其表面具有许多均匀分布的孔洞,这些孔洞形成了回风通道,用于电子芯片厂房等对空气洁净度有极高要求的环境。华夫板的设计和施工对于保证洁净室的功能发挥至关重要。…...

数据结构之链式结构二叉树的实现(进阶版)

本篇文章主要讲解链式二叉树的层序遍历以及判断是否为一棵完全二叉树 二者将会用到之前学过的队列知识&#xff0c;是将队列和二叉树的整合 一、如何将之前已经写好的文件加入当前的编译界面 如图所示&#xff0c;打开我们需要加入文件所在的文件夹&#xff0c;找到我们要加…...

【高等数学】3-2多元函数积分学

1. 二重积分 可以想象你有一块不规则的平面薄板,它在一个平面区域上。二重积分就是用来求这个薄板的质量(假设薄板的面密度函数是)。 把区域划分成许多非常小的小方块(类似于把一块地划分成很多小格子),在每个小方块上,密度近似看成是一个常数,然后把每个小方块的质量加…...

【传知代码】智慧医疗:纹理特征VS卷积特征

&#x1f351;个人主页&#xff1a;Jupiter. &#x1f680; 所属专栏&#xff1a;传知代码 欢迎大家点赞收藏评论&#x1f60a; 目录 论文概述纹理特征和深度卷积特征算法流程数据预处理方法纹理特征提取深度卷积特征提取分类网络搭建代码复现BLS_Model.py文件——分类器搭建py…...

Python-创建并调用自定义文件中的模块/函数

背景&#xff1a;在Python编程中&#xff0c;我们常常需要创建自己的专属文件&#xff0c;以便帮助我们更高效&#xff0c;快捷地完成任务。那么在Python中我们怎么创建并调用自己文件中的模块/函数呢? 在Python中调用自定义文件&#xff0c;通常是指调用自己编写的Python模块…...

Kali Linux

起源与背景 Kali Linux是一个基于Debian的开源Linux发行版&#xff0c;专门为信息安全工作者和渗透测试员设计。它是由Offensive Security Ltd.开发和维护的&#xff0c;作为BackTrack的继承者而诞生。BackTrack是一个流行的安全测试发行版&#xff0c;但为了提供更好的支持和…...

DiffusionDet: Diffusion Model for Object Detection—用于对象检测的扩散模型论文解析

DiffusionDet: Diffusion Model for Object Detection—用于对象检测的扩散模型论文解析 这是一篇发表在CVPR 2023的一篇论文&#xff0c;因为自己本身的研究方向是目标跟踪&#xff0c;之前看了一点使用扩散模型进行多跟踪的论文&#xff0c;里面提到了DiffusionDet因此学习一…...

深度学习基础知识-编解码结构理论超详细讲解

编解码结构&#xff08;Encoder-Decoder&#xff09;是一种应用广泛且高效的神经网络架构&#xff0c;最早用于序列到序列&#xff08;Seq2Seq&#xff09;任务&#xff0c;如机器翻译、图像生成、文本生成等。随着深度学习的发展&#xff0c;编解码结构不断演变出多种模型变体…...

探讨Java深搜算法的学习笔记

大家好&#xff0c;我是 V 哥。深度优先搜索&#xff08;DFS&#xff09;是一种图遍历算法&#xff0c;它优先深入到某条路径的尽头&#xff0c;再回溯到前一个节点继续探索其他路径&#xff0c;直到找到目标或遍历完整个图。DFS的应用场景广泛&#xff0c;可以用于路径搜索、连…...

408——操作系统(持续更新)

文章目录 一、操作系统的概念及特征1.1 计算机系统的概念1.2 操作系统的基本特征 二、操作系统的功能和接口2.1 操作系统作为计算机资源的管理者2.2 操作系统作为用户和计算机硬件系统之间的接口2.3 操作系统实现对计算机资源的扩充 三、操作系统的发展和分类四、操作系统的运行…...

架构师之路-学渣到学霸历程-37

Nginx的热部署实验 本次分享的就是nginx的升级以及降级&#xff0c;实验中其实很多操作都需要理解&#xff0c;实际操作不难&#xff0c;但是需要全面理解这个动作&#xff0c;敲这个命令是用来干什么的&#xff1f;借着这个笔记可以试一下&#xff1b;go~&#xff01; 1、ng…...

CSRF与SSRF

csrf(跨站请求伪造)的原理: csrf全称是跨站请求伪造(cross-site request forgery)&#xff0c;也被称为one-click attack 或者 session riding scrf攻击利用网站对于用户网页浏览器的信任&#xff0c;劫持用户当前已登录的web应用程序&#xff0c;去执行分用户本意的操作。 利…...

RabbitMQ 存储机制

一、消息存储机制 不管是持久化的消息还是非持久化的消息都可以被写入到磁盘。持久化的消息在到达队列时就被写入到磁盘&#xff0c;非持久化的消息一般只保存在内存中&#xff0c;在内存吃紧的时候会被换入到磁盘中&#xff0c;以节省内存空间。这两种类型的消息的落盘处理都…...

【Java SE】类型转换

类型转换是将一个值从一种类型转换为另一种类型的过程。该过程如果从低精度数据类型转为高精度数据类型&#xff0c;则不会发生溢出并且总能成功&#xff0c;如果从高精度数据类型转为低精度数据类型&#xff0c;则会有信息丢失且可能失败。类型转换又可分为隐式转换和显式转换…...

JAVA:常见 JSON 库的技术详解

1、简述 在现代应用开发中&#xff0c;JSON&#xff08;JavaScript Object Notation&#xff09;已成为数据交换的标准格式。Java 提供了多种方式将对象转换为 JSON 或从 JSON 转换为对象&#xff0c;常见的库包括 Jackson、Gson 和 org.json。本文将介绍几种常用的 JSON 处理…...

Redis缓存击穿、雪崩、穿透解决方案

Redis 缓存击穿、雪崩、穿透解决方案 1、首先看看逻辑方面是否还有优化空间&#xff0c;正常流程查询redis中获取不到数据&#xff0c;则去数据库获取&#xff0c;但数据库查询并返回时&#xff0c;调用异步方法&#xff0c;将该数据存储进redis中&#xff0c;并设置一个较短的…...

Python爬虫实战:研究MechanicalSoup库相关技术

一、MechanicalSoup 库概述 1.1 库简介 MechanicalSoup 是一个 Python 库,专为自动化交互网站而设计。它结合了 requests 的 HTTP 请求能力和 BeautifulSoup 的 HTML 解析能力,提供了直观的 API,让我们可以像人类用户一样浏览网页、填写表单和提交请求。 1.2 主要功能特点…...

shell脚本--常见案例

1、自动备份文件或目录 2、批量重命名文件 3、查找并删除指定名称的文件&#xff1a; 4、批量删除文件 5、查找并替换文件内容 6、批量创建文件 7、创建文件夹并移动文件 8、在文件夹中查找文件...

线程同步:确保多线程程序的安全与高效!

全文目录&#xff1a; 开篇语前序前言第一部分&#xff1a;线程同步的概念与问题1.1 线程同步的概念1.2 线程同步的问题1.3 线程同步的解决方案 第二部分&#xff1a;synchronized关键字的使用2.1 使用 synchronized修饰方法2.2 使用 synchronized修饰代码块 第三部分&#xff…...

YSYX学习记录(八)

C语言&#xff0c;练习0&#xff1a; 先创建一个文件夹&#xff0c;我用的是物理机&#xff1a; 安装build-essential 练习1&#xff1a; 我注释掉了 #include <stdio.h> 出现下面错误 在你的文本编辑器中打开ex1文件&#xff0c;随机修改或删除一部分&#xff0c;之后…...

深入理解JavaScript设计模式之单例模式

目录 什么是单例模式为什么需要单例模式常见应用场景包括 单例模式实现透明单例模式实现不透明单例模式用代理实现单例模式javaScript中的单例模式使用命名空间使用闭包封装私有变量 惰性单例通用的惰性单例 结语 什么是单例模式 单例模式&#xff08;Singleton Pattern&#…...

《通信之道——从微积分到 5G》读书总结

第1章 绪 论 1.1 这是一本什么样的书 通信技术&#xff0c;说到底就是数学。 那些最基础、最本质的部分。 1.2 什么是通信 通信 发送方 接收方 承载信息的信号 解调出其中承载的信息 信息在发送方那里被加工成信号&#xff08;调制&#xff09; 把信息从信号中抽取出来&am…...

MODBUS TCP转CANopen 技术赋能高效协同作业

在现代工业自动化领域&#xff0c;MODBUS TCP和CANopen两种通讯协议因其稳定性和高效性被广泛应用于各种设备和系统中。而随着科技的不断进步&#xff0c;这两种通讯协议也正在被逐步融合&#xff0c;形成了一种新型的通讯方式——开疆智能MODBUS TCP转CANopen网关KJ-TCPC-CANP…...

大语言模型(LLM)中的KV缓存压缩与动态稀疏注意力机制设计

随着大语言模型&#xff08;LLM&#xff09;参数规模的增长&#xff0c;推理阶段的内存占用和计算复杂度成为核心挑战。传统注意力机制的计算复杂度随序列长度呈二次方增长&#xff0c;而KV缓存的内存消耗可能高达数十GB&#xff08;例如Llama2-7B处理100K token时需50GB内存&a…...

算法笔记2

1.字符串拼接最好用StringBuilder&#xff0c;不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...

MySQL账号权限管理指南:安全创建账户与精细授权技巧

在MySQL数据库管理中&#xff0c;合理创建用户账号并分配精确权限是保障数据安全的核心环节。直接使用root账号进行所有操作不仅危险且难以审计操作行为。今天我们来全面解析MySQL账号创建与权限分配的专业方法。 一、为何需要创建独立账号&#xff1f; 最小权限原则&#xf…...