SpringBoot操作Redis缓存

SpringBoot操作Redis缓存

Redis有很多使用场景,一个使用场景就是缓存数据库的数据。Redis作为一个内存数据库,存取数据的速度比传

统的数据库快得多。使用Redis缓存数据库数据,可以减轻系统对数据库的访问压力,及加快查询效率等好处。下

面讲解如何使用 SpringBoot + Redis来缓存数据库数据(这里数据库使用MySql)。

Spring支持多种缓存技术:RedisCacheManagerEhCacheCacheManagerGuavaCacheManager等,使用之

前需要配置一个CacheManager的Bean。配置好之后使用三个注解来缓存数据:@Cacheable@CachePut

@CacheEvict。这三个注解可以加Service层或Dao层的类名上或方法上(建议加在Service层的方法上),加上类上

表示所有方法支持该注解的缓存;三注解需要指定Key,以返回值作为value操作缓存服务。所以,如果加在Dao

层,当新增1行数据时,返回数字1,会将1缓存到Redis,而不是缓存新增的数据。

1、使用的数据库脚本

create database redis_cache_test;
use redis_cache_test;
CREATE TABLE `sys_user` (`t_id` varchar(32) NOT NULL COMMENT 'ID编号',`t_name` varchar(300) DEFAULT NULL COMMENT '用户姓名',`t_age` int(11) DEFAULT NULL COMMENT '用户年龄',PRIMARY KEY (`t_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `sys_user` VALUES ('ID0001', 'zsx1', '27');
INSERT INTO `sys_user` VALUES ('ID0002', 'zsx2', '27');
INSERT INTO `sys_user` VALUES ('ID0003', 'zsx3', '27');
INSERT INTO `sys_user` VALUES ('ID0004', 'zsx4', '27');
INSERT INTO `sys_user` VALUES ('ID0005', 'zsx5', '18');
INSERT INTO `sys_user` VALUES ('ID0006', 'zsx6', '12');
INSERT INTO `sys_user` VALUES ('ID0007', 'zsx7', '8');

2、引入pom依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.5</version><relativePath/></parent><groupId>com.example</groupId><artifactId>spring-boot-redis-cache</artifactId><version>0.0.1-SNAPSHOT</version><name>spring-boot-redis-cache</name><description>spring-boot-redis-cache</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.9.6</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-annotations</artifactId><version>2.9.6</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.9.6</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

3、配置文件

# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=10
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1ms
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=1000mslogging.level.root=ERROR
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/redis_cache_test?characterEncoding=utf8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root

4、实体类User

package com.example.springbootrediscache.redis;/*** 简单的bean,对应DB的表*/
public class User {public User() {}public User(String id, String name, int age) {this.id = id;this.name = name;this.age = age;}@Overridepublic String toString() {return "User [id=" + id + ", name=" + name + ", age=" + age + "]";}private String id;private String name;private int age;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}
}

5、UserDao

package com.example.springbootrediscache.redis;import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;import java.util.List;@Mapper
@Component
public interface UserDao {/*** 插入数据** @param bean* @return*/@Insert("insert into sys_user       "+ "(t_id, t_name, t_age)    "+ "values                   "+ "(#{id}, #{name}, ${age}) ")int insertUser(User bean);/*** 查询所有数据** @return*/@ResultMap("redisUserDaoResults")@Select("select t_id, t_name, t_age "+ "from sys_user            ")List<User> selectUser();/*** 根据id查询数据** @param id* @return*/@Select("select t_id, t_age, t_name  "+ "from sys_user             "+ "where t_id = #{id}        ")@Results(id = "redisUserDaoResults", value = {@Result(property = "id", column = "t_id"),@Result(property = "age", column = "t_age"),@Result(property = "name", column = "t_name"),})User selectUserById(@Param("id") String id);/*** 根据id修改数据** @param user* @return*/@Update("update sys_user set  "+ "t_name = #{name},  "+ "t_age  = #{age}    "+ "where t_id = #{id} ")int updateUser(User user);/*** 根据id删除数据** @param id* @return*/@Delete("delete from sys_user  "+ "where t_id = #{id}  ")int deleteUserById(@Param("id") String id);}

6、RedisCacheUserDao

可以在Dao和Service任何一处使用缓存

package com.example.springbootrediscache.redis;import org.apache.ibatis.annotations.*;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;import java.util.List;@Component
@Mapper
@CacheConfig(cacheNames = "users")
public interface RedisCacheUserDao {// https://blog.csdn.net/f641385712/article/details/95169002@Cacheable(key = "#a0")@Select("select t_id, t_age, t_name  "+ "from sys_user             "+ "where t_id = #{id}        ")@Results(id = "redisUserDaoResults", value = {@Result(property = "id", column = "t_id"),@Result(property = "age", column = "t_age"),@Result(property = "name", column = "t_name"),})User selectUserById(@Param("id") String id);@Cacheable(key = "'list'")@ResultMap("redisUserDaoResults")@Select("select t_id, t_name, t_age "+ "from sys_user            ")List<User> selectUser();
}

7、RedisCacheUserService

package com.example.springbootrediscache.redis;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;import java.util.List;/*** 指定默认缓存区* 缓存区:key的前缀,与指定的key构成redis的key,如 user::10001*/
@CacheConfig(cacheNames = "user")
@Service
public class RedisCacheUserService {@Autowiredprivate UserDao dao;/*** @Cacheable 缓存有数据时,从缓存获取;没有数据时,将返回值保存到缓存中* @Cacheable 一般在查询中使用* 1) cacheNames 指定缓存区,没有配置使用@CacheConfig指定的缓存区* 2) key 指定缓存区的key* 3) 注解的值使用SpEL表达式* eq ==* lt <* le <=* gt >* ge >=*/@Cacheable(cacheNames = "user", key = "#id")public User selectUserById(String id) {return dao.selectUserById(id);}@Cacheable(key = "'list'")public List<User> selectUser() {return dao.selectUser();}/*** condition 满足条件缓存数据*/@Cacheable(key = "#id", condition = "#number ge 20") // >= 20public User selectUserByIdWithCondition(String id, int number) {return dao.selectUserById(id);}/*** unless 满足条件时否决缓存数据*/@Cacheable(key = "#id", unless = "#number lt 20") // < 20public User selectUserByIdWithUnless(String id, int number) {return dao.selectUserById(id);}/*** @CachePut 将返回值保存到缓存中* @CachePut 一般在新增和修改中使用*/@CachePut(key = "#user.id")public User insertUser(User user) {dao.insertUser(user);return user;}@CachePut(key = "#user.id", condition = "#user.age ge 20")public User insertUserWithCondition(User user) {dao.insertUser(user);return user;}@CachePut(key = "#user.id")public User updateUser(User user) {dao.updateUser(user);return user;}/*** 根据key删除缓存区中的数据*/@CacheEvict(key = "#id")public void deleteUserById(String id) {dao.deleteUserById(id);}/*** allEntries = true :删除整个缓存区的所有值,此时指定的key无效* beforeInvocation = true :默认false,表示调用方法之后删除缓存数据;true时,在调用之前删除缓存数据(如方法出现异常)*/@CacheEvict(key = "#id", allEntries = true)public void deleteUserByIdAndCleanCache(String id) {dao.deleteUserById(id);}
}

8、RedisConfig

RedisCacheManager的配置如下:

package com.example.springbootrediscache.redis;import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheManager.RedisCacheManagerBuilder;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;import java.time.Duration;@Configuration
@EnableCaching
@Slf4j
public class RedisConfig {/*** SpringBoot配置redis作为默认缓存工具* SpringBoot 2.0 以上版本的配置*/@Beanpublic CacheManager cacheManager(RedisTemplate<String, Object> template) {RedisCacheConfiguration defaultCacheConfiguration =RedisCacheConfiguration.defaultCacheConfig()// 设置key为String.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(template.getStringSerializer()))// 设置value为自动转Json的Object.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(template.getValueSerializer()))// 不缓存null.disableCachingNullValues()// 缓存数据保存1小时.entryTtl(Duration.ofHours(1));RedisCacheManager redisCacheManager =RedisCacheManagerBuilder// Redis 连接工厂.fromConnectionFactory(template.getConnectionFactory())// 缓存配置.cacheDefaults(defaultCacheConfiguration)// 配置同步修改或删除 put/evict.transactionAware().build();return redisCacheManager;}/*** redis template<String, Object>*/@Bean(name = "template")public RedisTemplate<String, Object> template(RedisConnectionFactory factory) {log.info("调用自定义的Redis Template!!!");// 创建RedisTemplate<String, Object>对象RedisTemplate<String, Object> template = new RedisTemplate<>();// 配置连接工厂template.setConnectionFactory(factory);// 定义Jackson2JsonRedisSerializer序列化对象Jackson2JsonRedisSerializer<Object> jacksonSeial = new Jackson2JsonRedisSerializer<>(Object.class);ObjectMapper om = new ObjectMapper();// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和publicom.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会报异常om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jacksonSeial.setObjectMapper(om);StringRedisSerializer stringSerial = new StringRedisSerializer();// redis key 序列化方式使用stringSerialtemplate.setKeySerializer(stringSerial);// redis value 序列化方式使用jacksontemplate.setValueSerializer(jacksonSeial);// redis hash key 序列化方式使用stringSerialtemplate.setHashKeySerializer(stringSerial);// redis hash value 序列化方式使用jacksontemplate.setHashValueSerializer(jacksonSeial);template.afterPropertiesSet();return template;}/*** 定义数据类型* string hash list set zset*//*** redis string*/@Beanpublic ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForValue();}/*** redis hash*/@Beanpublic HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForHash();}/*** redis list*/@Beanpublic ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForList();}/*** redis set*/@Beanpublic SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForSet();}/*** redis zset*/@Beanpublic ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForZSet();}
}

9、启动类

package com.example.springbootrediscache;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class SpringBootRedisCacheApplication {public static void main(String[] args) {SpringApplication.run(SpringBootRedisCacheApplication.class, args);}}

10、测试

mysql> select * from sys_user;
+--------+--------+-------+
| t_id   | t_name | t_age |
+--------+--------+-------+
| ID0001 | zsx1   |    27 |
| ID0002 | zsx2   |    27 |
| ID0003 | zsx3   |    27 |
| ID0004 | zsx4   |    27 |
| ID0005 | zsx5   |    18 |
| ID0006 | zsx6   |    12 |
| ID0007 | zsx7   |     8 |
+--------+--------+-------+
7 rows in set

10.1 RedisDaoCache

package com.example.springbootrediscache;import com.example.springbootrediscache.redis.RedisCacheUserDao;
import com.example.springbootrediscache.redis.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.junit4.SpringRunner;import java.util.List;@SpringBootTest(classes = SpringBootRedisCacheApplication.class)
@RunWith(SpringRunner.class)
public class RedisDaoCache {@Autowiredprivate RedisCacheUserDao dao;@Autowiredprivate ValueOperations<String, Object> redisString;@Testpublic void test001() {System.out.println("redis before use : " + redisString.get("users::ID0001"));System.out.println(dao.selectUserById("ID0001"));System.out.println("redis after use : " + redisString.get("users::ID0001"));}@Testpublic void test002() {System.out.println(redisString.get("users::list"));List<User> list = dao.selectUser();System.out.println(list.size());System.out.println(redisString.get("users::list"));}
}
@Test
public void test001() {System.out.println("redis before use : " + redisString.get("users::ID0001"));System.out.println(dao.selectUserById("ID0001"));System.out.println("redis after use : " + redisString.get("users::ID0001"));
}
redis before use : null
User [id=ID0001, name=zsx1, age=27]
redis after use : User [id=ID0001, name=zsx1, age=27]
@Test
public void test002() {System.out.println(redisString.get("users::list"));List<User> list = dao.selectUser();System.out.println(list.size());System.out.println(redisString.get("users::list"));
}
null
7
[User [id=ID0001, name=zsx1, age=27], User [id=ID0002, name=zsx2, age=27], User [id=ID0003, name=zsx3, age=27], User [id=ID0004, name=zsx4, age=27], User [id=ID0005, name=zsx5, age=18], User [id=ID0006, name=zsx6, age=12], User [id=ID0007, name=zsx7, age=8]]

10.2 RedisServiceCache

package com.example.springbootrediscache;import com.example.springbootrediscache.redis.RedisCacheUserService;
import com.example.springbootrediscache.redis.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.junit4.SpringRunner;import java.util.List;@SpringBootTest(classes = SpringBootRedisCacheApplication.class)
@RunWith(SpringRunner.class)
public class RedisServiceCache {@Autowiredprivate RedisCacheUserService service;@Autowiredprivate ValueOperations<String, Object> redisString;/*** 测试 @Cacheable 注解,缓存bean*/@Testpublic void test001() {// redis before use : null// User [id=ID0001, name=zsx, age=27]// redis after use : User [id=ID0001, name=zsx, age=27]System.out.println("redis before use : " + redisString.get("user::ID0001"));System.out.println(service.selectUserById("ID0001"));System.out.println("redis after use : " + redisString.get("user::ID0001"));System.out.println();// redis before use : User [id=ID0001, name=zsx, age=27]// User [id=ID0001, name=zsx, age=27]// redis after use : User [id=ID0001, name=zsx, age=27]System.out.println("redis before use : " + redisString.get("user::ID0001"));System.out.println(service.selectUserById("ID0001"));System.out.println("redis after use : " + redisString.get("user::ID0001"));System.out.println();}/*** 测试 @Cacheable 注解,缓存list* 'list':指定 list字符串作为key*/@Testpublic void test002() {// null// 3// [User [id=ID0001, name=zsx1, age=27], User [id=ID0002, name=zsx2, age=27], User [id=ID0003, name=zsx3, age=27]]System.out.println(redisString.get("user::list"));// 如果往数据库中插入数据,依然还是会从缓存中拿出,不会拿出最新的数据List<User> list = service.selectUser();System.out.println(list.size());System.out.println(redisString.get("user::list"));}/*** 测试 @Cacheable 注解的 condition : 满足条件时缓存数据*/@Testpublic void test003() {// User [id=ID0002, name=zsx2, age=27]// redis data[ID0002] : nullUser user1 = service.selectUserByIdWithCondition("ID0002", 19);System.out.println(user1);System.out.println("redis data[ID0002] : " + redisString.get("user::ID0002"));// User [id=ID0003, name=zsx3, age=27]// redis data[ID0003]: User [id=ID0003, name=zsx3, age=27]User user2 = service.selectUserByIdWithCondition("ID0003", 20);System.out.println(user2);System.out.println("redis data[ID0003]: " + redisString.get("user::ID0003"));}/*** 测试 @Cacheable 注解的 unless : 满足条件时不缓存数据*/@Testpublic void test004() {// User [id=ID0004, name=zsx4, age=27]// redis data[ID0004] : nullUser user1 = service.selectUserByIdWithUnless("ID0004", 19);System.out.println(user1);System.out.println("redis data[ID0004] : " + redisString.get("user::ID0004"));// User [id=ID0005, name=zsx5, age=18]// redis data[ID0005]: User [id=ID0005, name=zsx5, age=18]User user2 = service.selectUserByIdWithUnless("ID0005", 20);System.out.println(user2);System.out.println("redis data[ID0005]: " + redisString.get("user::ID0005"));}/*** 测试 @CachePut 注解*/@Testpublic void test005() {User user = new User("10086", "insert_name", 11);service.insertUser(user);// User [id=10086, name=insert_name, age=11]System.out.println(redisString.get("user::10086"));User user2 = new User("10087", "insert_name", 22);service.insertUserWithCondition(user2);// User [id=10087, name=insert_name, age=22]System.out.println(redisString.get("user::10087"));User user3 = new User("10086", "update_name", 12);service.updateUser(user3);// User [id=10086, name=update_name, age=12]System.out.println(redisString.get("user::10086"));}/*** 测试 @CacheEvict 注解*/@Testpublic void test006() {// [user::ID0003, user::ID0001, user::10086, user::list, user::10087, user::ID0005]System.out.println(redisString.getOperations().keys("user::*"));service.deleteUserById("10086");// [user::ID0003, user::ID0001, user::list, user::10087, user::ID0005]System.out.println(redisString.getOperations().keys("user::*"));service.deleteUserByIdAndCleanCache("10087");// []System.out.println(redisString.getOperations().keys("user::*"));}
}

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

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

相关文章

听GPT 讲Rust源代码--src/tools(15)

File: rust/src/tools/rust-analyzer/crates/mbe/src/token_map.rs 在Rust源代码中&#xff0c;rust/src/tools/rust-analyzer/crates/mbe/src/token_map.rs文件的作用是实现了一个能够将输入的文本映射为标记的结构。具体来说&#xff0c;它定义和实现了几个结构体&#xff08…

【已解决】Mysql在更新的时候,需要更新的字段是其他表查询的值,这个时候update语句怎么写

Mysql在更新的时候,需要更新的字段是其他表查询的值&#xff0c;这个时候update语句怎么写&#xff1f; 例如&#xff1a;我想要更新A表中的floor字段。但是这个字段的是是根据条件在B表中查询后&#xff0c;得到的值。 这样需求的sql语句怎么写 &#xff1f; 要点&#xff…

Mysql5.7版本中,查询分组GROUP BY通过子查询中ORDER BY进行排序无效的问题解决办法

文章目录 一、场景&#xff1a;二、解决办法1、使用 having 来阻止合并2、足够大的limit3、子查询 一、场景&#xff1a; 问题描述&#xff1a;Mysql5.7版本中&#xff0c;查询分组GROUP BY通过子查询中ORDER BY进行排序无效的问题解决办法。 应用场景&#xff1a;一对多的关系…

数据库(三)超详细SQL语句入门 | SQL增删改查,重命名,字符操作,联合操作,聚合函数,嵌套子查询

文章目录 1 SQL表内类型2 SQL增删改语句2.1 创建表2.2 删除表2.3 表中添加属性2.4 添加新的元组信息2.5 删除表所有元组2.6 元组 3 查询语句4 重命名4.1 为什么用 5 字符操作5.1 寻找 6 生序降序7 联合操作7.1 并集Union7.2 交集 INTERSECT7.3 差集 EXCEPT7.4 对于空值补充 8 聚…

掀起全新的互联网直播风潮

随着科技的不断进步和智能手机的普及&#xff0c;无人直播作为一种全新的互联网直播方式&#xff0c;在近些年迅速崛起&#xff0c;并引起了广泛关注。本文将围绕手机无人直播展开探讨&#xff0c;探究其背后的原因以及对社会生活带来的影响。 首先&#xff0c;我们需要明确什…

[Angular] 笔记 5:ngClass

Angular 中的 ngClass 是什么&#xff1f; chatgpt 回答&#xff1a; 在Angular中&#xff0c;ngClass 是一个内置的指令&#xff0c;用于动态地添加或移除 HTML 元素的 CSS 类。它允许你根据条件设置一个或多个 CSS 类&#xff0c;可以是对象、数组或字符串。 使用方式&#…

一篇文章带你进阶CTF命令执行

以下的命令是为了方便以后做题时方便各位读者直接来这里复制使用&#xff0c;刚开始还请先看完这篇文章后才会懂得下面的命令 ?ceval($_GET[shy]);&shypassthru(cat flag.php); #逃逸过滤 ?cinclude%09$_GET[shy]?>&shyphp://filter/readconvert.base64-…

mysql:查看服务端没有睡眠的线程数量

使用命令show global status like Threads_running;可以查看服务端没有睡眠的线程数量。 例如&#xff1a;

使用React和ResizeObserver实现自适应ECharts图表

关键词 React ECharts ResizeObserver 摘要 在现代 Web 开发中&#xff0c;响应式布局和数据可视化是非常常见的需求。本文将介绍如何使用React、ResizeObserver和ECharts库来创建一个自适应的图表组件。 什么是ResizeObserver ResizeObserver是JavaScript的一个API&#x…

定时任务,停用用户。

1&#xff0c; <!-- 定时3.用户三个月无操作&#xff0c;停用用户 begin --> <bean id"autoStopSleepUserService" class"com.rjhc.application.sysmanage.service.impl.SysTaskScheduleServiceImpl" /> <bean id"jobDetail_…

玩转Spring状态机

说起Spring状态机&#xff0c;大家很容易联想到这个状态机和设计模式中状态模式的区别是啥呢&#xff1f;没错&#xff0c;Spring状态机就是状态模式的一种实现&#xff0c;在介绍Spring状态机之前&#xff0c;让我们来看看设计模式中的状态模式。 1. 状态模式 状态模式的定义如…

代码随想录 322. 零钱兑换

题目 给你一个整数数组 coins &#xff0c;表示不同面额的硬币&#xff1b;以及一个整数 amount &#xff0c;表示总金额。 计算并返回可以凑成总金额所需的 最少的硬币个数 。如果没有任何一种硬币组合能组成总金额&#xff0c;返回 -1 。 你可以认为每种硬币的数量是无限的。…

[Encryptedd@mailfence.com].faust 勒索病毒肆虐:如何恢复被加密的数据文件?

导言&#xff1a; 在网络安全的战场上&#xff0c;[backupsairmail.cc].faust [Deciphermailfence.com].faust[Encrypteddmailfence.com].faust[support2022cock.li].faust [tsai.shenmailfence.com].faust勒索病毒是一种极具破坏性的恶意软件。本文91数据恢复将深入介绍该病毒…

Docker仓库

官方docker仓库使用 网址&#xff1a;https://hub.docker.com 每个注册用户都可以上传和管理自己的镜像 用户登录 上传镜像前需要登陆&#xff0c;登陆后生成~/.docker/config.json文件保存验证信息 docker login 给本地镜像打标签 上传本地镜像前必须先给上传的镜像用do…

【krita】实时绘画 入门到精通 海报+电商+装修+人物

安装插件 首先打开comfyUI&#xff0c;再打开krita&#xff0c;出现问题提示&#xff0c; 打开 cd custom_nodes 输入命令 安装控件 git clone https://github.com/Acly/comfyui-tooling-nodes.git krita基础设置 设置模型 设置lora &#xff08;可设置lora强度 增加更多…

◢Django md5加密与中间件middleware

utils文件夹是重新建立的&#xff08;与migrations同级&#xff09;&#xff0c;该文件夹下主要存放工具&#xff0c;就像static文件夹下只存放静态文件一样 加密 在utils文件夹下建立encrypt.py文件 from django.conf import settings import hashlib def md5(data_string)…

Airtest1.2.7新增断言API介绍

1. 前言 1.2.7版本的Airtest中&#xff0c;一个很重要的功能是 新增了非常丰富的断言API &#xff0c;今天我们就来详细看一下Airtest都给我们提供了哪些断言语句。 2. 旧版Airtest提供的断言语句 先回顾下&#xff0c;旧版Airtest一直以来&#xff0c;都只给我们提供了2种断言…

Samtec信号完整性 这家连接器的设计很优秀!

【Samtec技术研发&#xff1a;信号完整性设计】 1. 什么是信号完整性&#xff1f; 信号完整性需要在整个系统和组件设计过程中加以考虑。与过去不同的是&#xff0c;互连不再是事后考虑的问题。随着上升时间的缩短和时钟频率的提高&#xff0c;曾经被认为是电气透明的连接器和…

阿里云经济型、通用算力型、计算型、通用型、内存型云服务器最新活动报价

阿里云作为国内领先的云计算服务提供商&#xff0c;提供了多种规格的云服务器供用户选择。为了满足不同用户的需求&#xff0c;阿里云推出了经济型、通用算力型、计算型、通用型和内存型等不同类型的云服务器。下面将详细介绍这些云服务器的最新活动报价。 一、阿里云特惠云服…

机器学习数据的清洗,转化,汇总及建模完整步骤(基于Titanic数据集)

目录 介绍&#xff1a; 一、数据 二、检查数据缺失 三、数据分析 四、数据清洗 五、数据类别转化 六、数据汇总和整理 七、建模 介绍&#xff1a; 线性回归是一种常用的机器学习方法&#xff0c;用于建立一个输入变量与输出变量之间线性关系的预测模型。线性回归的目标…