SpringBoot1.x 缓存

文章源码

JSR107

Java Caching 定义了 5 个核心接口,分别为:

  • CachingProvider 定义了创建、配置、获取、管理和控制多个 CacheManager。一个应用可以在运行期访问多个 CachingProvider。
  • CacheManager 定义了创建、配置、获取、管理和控制多个唯一命名的 Cache,这些 Cache 存在于 CacheManager 的上下文中。一个 CacheManager 仅被一个 CachingProvider 拥有。
  • Cache 是一个类似 Map 的数据结构并临时存储以 Key 为索引的值。一个 Chache 仅被一个 CacheManager 拥有。
  • Entry 是一个存储在 Cache 中的 key-value 对。
  • Expiry 指每一个存储在 Chche 中的条目有一个定义的有效期,一旦超过这个时间,条目就为过期的状态。一旦过期,条目将不可访问、更新和删除。有效期可以通过 ExpiryPolicy 设置。

Spring 缓存抽象

Spring3.1 后定义了 org.springframework.cache.Cacheorg.springframework.cache.CacheManager 接口来统一不同的缓存技术,并支持使用 JCache(JSR107) 注解简化我们开发。

  • Cache 接口 为缓存的组件规范定义,包含缓存的各种操作集合;
  • Cache 接口下 Spring 提供了各种 xxxCache 的实现,如 RedisCache、EhCacheCache、ConcurrentMapCache等;
  • 每次调用需要缓存功能的方法时,Spring 会检查指定参数的指定目标方法是否被调用过。如果有就直接从缓存中获取方法调用后的结果,如果没有就调用方法就缓存结果后返回给用户。下次调用直接从缓存中获取。
  • 使用 Spring 缓存抽象需注意:
    • 确定方法需要被缓存以及它们的缓存策略;
    • 从缓存中读取之前缓存存储的数据。

重要概念及缓存注解

  • Chche 缓存接口,定义缓存操作。实现有 RedisCache、EhCacheCache、ConcurrentMapCache等。
  • ChacheManager 缓存管理器,管理各种缓存组件。
  • @EnableCaching 开启基于注解的缓存,用在主配置类上。
  • @Cacheable 能够根据方法的请求参数对其结果进行缓存
  • @CachePut 即调用方法,又更新缓存数据
  • @CacheEvict 清除缓存
  • @Caching 定义复杂的缓存规则

@Cacheable@CachePut@Caching 等注解主要的参数:

  • cacheNames/value 缓存的名字,即将方法的返回结果放在那个缓存中,可以指定多个
  • key 缓存的数据,为空时默认是使用方法参数的值,可以为 SpEL 表达式,例如 #id
  • keyGenerator key 的生成器,可以自己指定 key 的生成器的组件 id,它与 key 二选一
  • cacheManager 缓存管理器
  • cacheResolver 缓存解析器,它与 cacheManager 二选一
  • condition 执行符合条件才缓存
  • unless 执行不符合条件才缓存
  • sync 是否使用异步模式
  • allEntries 是否清空所有缓存,默认为 false,如果指定为 true,则方法调用后将立即清空所有缓存
  • beforeInvocation 默认为 false,即缓存清除操作是在方法之后执行,出现异常不会清除缓存。如果指定为 true,即缓存清除操作是在方法之前执行。无论是否出现异常,缓存都会清除

SpEL 表达式

名字 位置 描述 示例
methodName root object 当前被调用的方法名 #root.methodName
method root object 当前被调用的方法 #root.method.name
target root object 当前被调用的目标对象 #root.target
targetClass root object 当前被调用的目标对象类 #root.targetClass
args root object 当前被调用的方法的参数列表 #root.args[0]
caches root object 当前方法调用使用的缓存列表,例如@Cacheable(value={"cache1", "cache2"}),则有两个 cache #root.caches[0].name
argument name evaluation context 方法参数的名字,可以直接 #参数名,也可以使用 #p0#a0 的形式,0 代表参数的索引 #id#a0#p0
result evaluation context 方法执行后的返回值,仅当方法执行之后的判断有效 #result

缓存使用

使用步骤

  • 第一步:建立相应表结构
  • 第二步:编写相应的实体类
  • 第三步:整合 MyBatis
    • 配置数据源信息
    • 使用注解版的 Mybatis,即在主配置类上加上 @MapperScan
  • 第四步:使用缓存
    • 在主配置类上加上 @EnableCaching
    • 在业务层方法加上 @Cacheable@CachePut@CacheEvict@Caching 等注解

缓存配置原理

  • 使用 CacheAutoConfiguration 自动配置类
  • 扫描到各种缓存的配置类:
    • org.springframework.boot.autoconfigure.cache.GenericCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.EhCacheCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.HazelcastCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.InfinispanCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.CouchbaseCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.RedisCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.CaffeineCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.GuavaCacheConfiguration
    • org.springframework.boot.autoconfigure.cache.SimpleCacheConfiguration,这是默认生效的
    • org.springframework.boot.autoconfigure.cache.NoOpCacheConfiguration
  • 给容器中注册了一个 CacheManager,默认是 ConcurrentMapCacheManager
  • 创建和获取 ConcurrentMapCache 类型的缓存组件,它的作用是将数据保存在 ConcurrentMap 中

EmployeeService:

  1. /**
  2. * @Author : parzulpan
  3. * @Time : 2020-12
  4. * @Desc : 员工业务层
  5. */
  6. @Service
  7. public class EmployeeService {
  8. @Autowired
  9. EmployeeMapper employeeMapper;
  10. /**
  11. *
  12. * 根据 Id 查询员工信息
  13. *
  14. * @Cacheable 运行流程:
  15. * 1. 方法运行之前,先去查询 Cache 缓存组件,按照 cacheNames 指定的名字获取,第一次获取缓存时如果没有 Cache 组件会自动创建
  16. * 2. 去 Cache 中查询缓存的内容,使用一个 key,默认是方法的参数。也可以按照某种策略生成,默认使用 SimpleKeyGenerator 生成 key
  17. * SimpleKeyGenerator 生成 key 的默认策略为:
  18. * 如果没有参数,key = new SimpleKey()
  19. * 如果有一个参数,key = 参数的值
  20. * 如果有多个参数,key = new SimpleKey(params)
  21. * 3. 有查询到缓存,则直接使用缓存;没有查询到缓存,则调用目标方法并将目标方法返回的结果放进缓存中
  22. */
  23. @Cacheable(cacheNames = {"emp"})
  24. public Employee getEmp(Integer id) {
  25. return employeeMapper.getEmpById(id);
  26. }
  27. /**
  28. *
  29. * 更新员工信息
  30. *
  31. * @CachePut 运行流程
  32. * 1. 先调用目标方法
  33. * 2. 将目标方法的结果缓存起来
  34. * 3. 比较适用与修改了数据库某个数据后,更新缓存
  35. */
  36. @CachePut(value = {"emp"}, key = "#result.id")
  37. public Employee updateEmp(Employee employee) {
  38. employeeMapper.updateEmp(employee);
  39. return employee;
  40. }
  41. /**
  42. *
  43. * 删除员工信息
  44. *
  45. */
  46. @CacheEvict(value = {"emp"}, key = "#id")
  47. public void deleteEmp(Integer id) {
  48. employeeMapper.deleteEmpById(id);
  49. }
  50. /**
  51. *
  52. * 根据 lastName 查询员工信息
  53. *
  54. * @Caching 定义复杂的缓存规则
  55. */
  56. @Caching(
  57. cacheable = {
  58. @Cacheable(value = {"emp"}, key = "#lastName")
  59. },
  60. put = {
  61. @CachePut(value = {"emp"}, key = "#result.id"),
  62. @CachePut(value = {"emp"}, key = "#result.email")
  63. }
  64. )
  65. public Employee getEmp(String lastName) {
  66. List<Employee> employees = employeeMapper.getEmpByName(lastName);
  67. if (employees.isEmpty()) {
  68. return null;
  69. }
  70. return employees.get(0);
  71. }
  72. }

EmployeeController:

  1. /**
  2. * @Author : parzulpan
  3. * @Time : 2020-12
  4. * @Desc : 员工控制器
  5. */
  6. @RestController
  7. public class EmployeeController {
  8. @Autowired
  9. EmployeeService employeeService;
  10. // http://localhost:8080/emp/1
  11. @GetMapping("/emp/{id}")
  12. public Employee getEmp(@PathVariable("id") Integer id) {
  13. return employeeService.getEmp(id);
  14. }
  15. // http://localhost:8080/emp?id=1&lastName=ha&email=ha@gmail.com&gender=0&dId=1001
  16. @GetMapping("/emp")
  17. public Employee updateEmp(Employee employee) {
  18. return employeeService.updateEmp(employee);
  19. }
  20. // http://localhost:8080/empDel?id=1
  21. @GetMapping("/empDel")
  22. public String deleteEmp(Integer id) {
  23. employeeService.deleteEmp(id);
  24. return "success";
  25. }
  26. // http://localhost:8080/emp/lastName/parzulpan
  27. @GetMapping("/emp/lastName/{lastName}")
  28. public Employee getEmp(@PathVariable("lastName") String lastName) {
  29. return employeeService.getEmp(lastName);
  30. }
  31. }

开启 debug 配置后,可以观察缓存的作用:

  1. logging:
  2. level:
  3. cn.parzulpan.mapper: debug

可以使用 @CacheConfig,它指定这个类的缓存配置,通常用于抽取公共配置。

  1. @CacheConfig(cacheNames = {"emp"})
  2. @Service
  3. public class EmployeeService {}

整合 Redis

使用步骤:

  • 引入 Redis 启动器依赖

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-data-redis</artifactId>
    4. </dependency>
  • 配置 Redis

    1. spring:
    2. # 配置 Redis
    3. redis:
    4. host: localhost
  • 测试 Redis

    1. @RunWith(SpringRunner.class)
    2. @SpringBootTest
    3. public class IntegrationCacheApplicationTests {
    4. @Autowired
    5. RedisTemplate redisTemplate; // k-v 都是对象
    6. @Autowired
    7. StringRedisTemplate stringRedisTemplate; // k-v 都是字符串
    8. @Test
    9. public void testRedisString() {
    10. // 字符串操作
    11. // String 类型 是 Redis 中最基本的数据类型,一个 key 对应一个 value 。
    12. stringRedisTemplate.opsForValue().set("stringMsg", "hello");
    13. stringRedisTemplate.opsForValue().append("stringMsg", "world");
    14. String msg = stringRedisTemplate.opsForValue().get("stringMsg");
    15. System.out.println(msg);
    16. }
    17. @Test
    18. public void testRedisList() {
    19. // 列表操作
    20. // List 类型 是简单的字符串列表,按照插入顺序排序。可以添加一个元素到列表的头部(左边)或者尾部(右边)。
    21. ListOperations<String, String> ops = redisTemplate.opsForList();
    22. ops.leftPush("listMsg", "hello");
    23. ops.leftPushAll("listMsg", "world", "parzulpan");
    24. List<String> listMsg = ops.range("listMsg", 0, 2);// 索引 0 到2的 listMsg
    25. System.out.println(listMsg.toString());
    26. }
    27. @Test
    28. public void testRedisSet() {
    29. // 集合操作
    30. // Set 类型 是 String 类型 的无序集合。它的特点是无序且唯一,它是通过哈希表实现的,所以添加、删除、查找的复杂度都是 O(1)。
    31. SetOperations<String, String> ops = redisTemplate.opsForSet();
    32. ops.add("setMsg", "hello");
    33. ops.add("setMsg", "world", "parzulpan");
    34. Set<String> setMsg = ops.members("setMsg"); // 取 set
    35. System.out.println(setMsg.toString());
    36. }
    37. @Test
    38. public void testRedisZSet() {
    39. // 有序集合操作
    40. // ZSet 类型 和 Set 类型 一样,也是 String 类型元素的集合,且不允许有重复的成员。
    41. // 不同的是每个元素都会关联一个 double 类型 的分数,它正是通过分数来为集合中的成员进行从小到大的排序。
    42. // ZSet 类型的成员是唯一的,但分数(score) 却可以重复。
    43. ZSetOperations<String, String> ops = redisTemplate.opsForZSet();
    44. ops.add("zsetMsg", "hello", 1);
    45. ops.add("zsetMsg", "parzulpan", 3);
    46. ops.add("zsetMsg", "world", 2);
    47. Set<String> zsetMsg = ops.range("zsetMsg", 0, 2);
    48. System.out.println(zsetMsg.toString());
    49. }
    50. @Test
    51. public void testRedisHash() {
    52. // 哈希操作
    53. // Hash 类型 是一个键值对的集合。它是一个 String 类型 的 field 和 value 组合的映射表,它特别适合用于存储对象。
    54. HashOperations<String, String, String> ops = redisTemplate.opsForHash();
    55. ops.put("hashMsg", "key1", "hello");
    56. ops.put("hashMsg", "key2", "world");
    57. ops.put("hashMsg", "key3", "parzulpan");
    58. String key2 = ops.get("hashMsg", "key2");
    59. System.out.println(key2);
    60. }
    61. }
  • 对于上面的测试,Redis 默认保存对象,使用 JDK 序列化机制,序列化后的数据保存到 redis 中。可以使用自定义的序列化器。值得注意的是,无论是 json 序列化还是 jdk 序列化,redis 接受的都是字符串的文本,而 jdk 的序列化方式字符串会把 json 序列化方式字符串大几倍,性能较差,所以一般都使用自定义的序列化器。

    1. /**
    2. * @Author : parzulpan
    3. * @Time : 2021-01
    4. * @Desc : 自定义 Redis 配置类
    5. */
    6. @Configuration
    7. public class CustomRedisConfig {
    8. // 使用 Jackson 序列化器,不使用默认的 JDK 的
    9. @Bean
    10. public RedisTemplate<Object, Employee> employeeRedisTemplate(RedisConnectionFactory rcf){
    11. RedisTemplate<Object, Employee> template = new RedisTemplate<>();
    12. template.setConnectionFactory(rcf);
    13. Jackson2JsonRedisSerializer<Employee> jrs = new Jackson2JsonRedisSerializer<>(Employee.class);
    14. template.setDefaultSerializer(jrs);
    15. return template;
    16. }
    17. }
    1. @RunWith(SpringRunner.class)
    2. @SpringBootTest
    3. public class IntegrationCacheApplicationTests {
    4. @Autowired
    5. RedisTemplate employeeRedisTemplate; // 使用自定义的 RedisTemplate
    6. @Test
    7. public void testEmployeeRedisTemplate() {
    8. ValueOperations ops = employeeRedisTemplate.opsForValue();
    9. Employee employee = employeeMapper.getEmpById(1);
    10. ops.set("emp-01", employee);
    11. }
    12. }
  • 使用 Redis 缓存,它的原理是:

    • CacheManager,生成一个 Cache 缓存组件来实际给缓存中存取数据

    • 引入 redis 的 starter,容器中保存的是 RedisCacheManager;

    • RedisCacheManager 帮我们创建 RedisCache 来作为缓存组件,RedisCache 通过操作 redis 缓存数据

    • 默认保存数据 k-v 都是 Object。利用序列化保存,所以实体类需要继承 Serializable。它默认使用的是 RedisTemplate<Object, Object>,它是 jdk 默认的序列化机制

    • 可以通过自定义 CacheManager,更改序列化机制:

      1. /**
      2. * @Author : parzulpan
      3. * @Time : 2021-01
      4. * @Desc : 自定义 Redis 配置类
      5. */
      6. @Configuration
      7. public class CustomRedisConfig {
      8. // 使用 Jackson 序列化器,不使用默认的 JDK 的
      9. @Bean
      10. public RedisTemplate<Object, Employee> employeeRedisTemplate(RedisConnectionFactory rcf){
      11. RedisTemplate<Object, Employee> template = new RedisTemplate<>();
      12. template.setConnectionFactory(rcf);
      13. Jackson2JsonRedisSerializer<Employee> jrs = new Jackson2JsonRedisSerializer<>(Employee.class);
      14. template.setDefaultSerializer(jrs);
      15. return template;
      16. }
      17. // 自定义缓存管理器
      18. @Bean
      19. public RedisCacheManager employeeCacheManager(RedisTemplate<Object, Employee> employeeRedisTemplate) {
      20. RedisCacheManager redisCacheManager = new RedisCacheManager(employeeRedisTemplate);
      21. // 使用前缀,默认将 CacheName 作为 key 的前缀
      22. redisCacheManager.setUsePrefix(true);
      23. return redisCacheManager;
      24. }
      25. }
  • 使用示例:

    1. /**
    2. * @Author : parzulpan
    3. * @Time : 2021-01
    4. * @Desc : 部门业务层
    5. */
    6. @Service
    7. public class DepartmentService {
    8. @Autowired
    9. DepartmentMapper departmentMapper;
    10. @Autowired
    11. RedisCacheManager departmentCacheManager;
    12. // 注解的方式
    13. @Cacheable(cacheNames = "dept", cacheManager = "departmentCacheManager")
    14. public Department getDeptById(Integer id) {
    15. return departmentMapper.getDeptById(id);
    16. }
    17. // api 调用的方式
    18. public Department getDeptById2(Integer id) {
    19. Department department = departmentMapper.getDeptById(id);
    20. // 获取某个缓存
    21. Cache dept = departmentCacheManager.getCache("dept");
    22. dept.put("dept2:" + id, department);
    23. return department;
    24. }
    25. }

总之,相对于默认的 Cache,使用 Redis,需要多写如下的一个 Redis 配置类:

  1. /**
  2. * @Author : parzulpan
  3. * @Time : 2021-01
  4. * @Desc : 自定义 Redis 配置类
  5. */
  6. @Configuration
  7. public class CustomRedisConfig {
  8. // 使用 Jackson 序列化器,不使用默认的 JDK 的
  9. @Bean
  10. public RedisTemplate<Object, Employee> employeeRedisTemplate(RedisConnectionFactory rcf){
  11. RedisTemplate<Object, Employee> template = new RedisTemplate<>();
  12. template.setConnectionFactory(rcf);
  13. Jackson2JsonRedisSerializer<Employee> jrs = new Jackson2JsonRedisSerializer<>(Employee.class);
  14. template.setDefaultSerializer(jrs);
  15. return template;
  16. }
  17. @Bean
  18. public RedisTemplate<Object, Department> departmentRedisTemplate(RedisConnectionFactory rcf){
  19. RedisTemplate<Object, Department> template = new RedisTemplate<>();
  20. template.setConnectionFactory(rcf);
  21. Jackson2JsonRedisSerializer<Department> jrs = new Jackson2JsonRedisSerializer<>(Department.class);
  22. template.setDefaultSerializer(jrs);
  23. return template;
  24. }
  25. // 自定义缓存管理器
  26. @Primary // 将其作为默认的
  27. @Bean
  28. public RedisCacheManager employeeCacheManager(RedisTemplate<Object, Employee> employeeRedisTemplate) {
  29. RedisCacheManager redisCacheManager = new RedisCacheManager(employeeRedisTemplate);
  30. // 使用前缀,默认将 CacheName 作为 key 的前缀
  31. redisCacheManager.setUsePrefix(true);
  32. return redisCacheManager;
  33. }
  34. @Bean
  35. public RedisCacheManager departmentCacheManager(RedisTemplate<Object, Department> departmentRedisTemplate) {
  36. RedisCacheManager redisCacheManager = new RedisCacheManager(departmentRedisTemplate);
  37. // 使用前缀,默认将 CacheName 作为 key 的前缀
  38. redisCacheManager.setUsePrefix(true);
  39. return redisCacheManager;
  40. }
  41. }

练习和总结

【SpringBoot1.x】SpringBoot1.x 缓存的更多相关文章

  1. springboot1 缓存前端

    @Configurationpublic class WebMvcConfig extends WebMvcConfigurerAdapter { public void addResourceHan ...

  2. 【SpringBoot1.x】SpringBoot1.x 数据访问

    SpringBoot1.x 数据访问 简介 对于数据访问层,无论是 SQL 还是 NOSQL,Spring Boot 默认采用整合 Spring Data 的方式进行统一处理,添加大量自动配置,屏蔽了 ...

  3. 【SpringBoot1.x】RestfulCRUD

    SpringBoot1.x RestfulCRUD 文章源码 添加资源 将所有的静态资源都添加到 src/main/resources/static 文件夹下,所有的模版资源都添加到 src/main ...

  4. 【SpringBoot1.x】SpringBoot1.x Web 开发

    SpringBoot1.x Web 开发 文章源码 简介 SpringBoot 非常适合 Web 应用程序开发.可以使用嵌入式 Tomcat,Jetty 或 Undertow 轻松创建独立的 HTTP ...

  5. 记 SpringBoot1.* 转 Springoot2.0 遇到的问题

    1.拦截器问题 到2.0之后在配置文件中写 static-path-pattern: /static/** 已经不起作用(2.0需要在方法中配置) SpringBoot1.*写法 @Configura ...

  6. SpringBoot1.x与监控(六)

    由于2.x和1.x的监控不一样,此处先讲1.x 一 SpringBoot1.x监控 pom.xml <dependency> <groupId>org.springframew ...

  7. SpringBoot1.x升级SpringBoot2.x踩坑之文件上传大小限制

    SpringBoot1.x升级SpringBoot2.x踩坑之文件上传大小限制 前言 LZ最近升级SpringBoo框架到2.1.6,踩了一些坑,这里介绍的是文件上传大小限制. 升级前 #文件上传配置 ...

  8. 使用SpringBoot1.4.0的一个坑

    时隔半年,再次使用Spring Boot快速搭建微服务,半年前使用的版本是1.2.5,如今看官网最新的release版本是1.4.0,那就用最新的来构建,由于部署环境可能有多套所以使用maven-fi ...

  9. springboot1.5和jpa利用HikariCP实现多数据源的使用

    背景 现在已有一个完整的项目,需要引入一个新的数据源,其实也就是分一些请求到从库上去 技术栈 springboot1.5 (哎,升不动啊) 思路 两个数据源,其中一个设置为主数据源 两个事物管理器,其 ...

随机推荐

  1. filereader 和 window.URL.createObjectURL

    <template> <div class="file-preview"> <h4>前端图片预览之 filereader 和 window.UR ...

  2. Java程序执行过程及内存机制

    本讲将介绍Java代码是如何一步步运行起来的,其中涉及的编译器,类加载器,字节码校验器,解释器和JIT编译器在整个过程中是发挥着怎样的作用.此外还会介绍Java程序所占用的内存是被如何管理的:堆.栈和 ...

  3. Spring Boot 日志各种使用姿势,是时候捋清楚了!

    @ 目录 1. Java 日志概览 1.1 总体概览 1.2 日志级别 1.3 综合对比 1.4 最佳实践 2. Spring Boot 日志实现 2.1 Spring Boot 日志配置 2.2 L ...

  4. Java——排序算法

    java排序从大的分类来看,可以分为内排序和外排序:其中,在排序过程中只使用了内存的排序称为内排序:内存和外存结合使用的排序成为外排序. 下面讲的都是内排序. 内排序在细分可以这样分: 1.选择排序: ...

  5. css 08-CSS属性:定位属性

    08-CSS属性:定位属性 CSS的定位属性有三种,分别是绝对定位.相对定位.固定定位. position: absolute; <!-- 绝对定位 --> position: relat ...

  6. 2、MyCat读写分离

    1.主从复制 搭建mycat的读写分离,首先我们现需要搭建mysql的主从复制 [1].Mysql主从复制原理 [2].MySQL主从复制配置 (1).主机配置 修改配置文件:vim /etc/my. ...

  7. Spring Data JPA 的 Specifications动态查询

    主要的结构: 有时我们在查询某个实体的时候,给定的条件是不固定的,这时就需要动态构建相应的查询语句,在Spring Data JPA中可以通过JpaSpecificationExecutor接口查询. ...

  8. Spring Cloud 入门教程(二): 服务消费者(rest+ribbon)

    在上一篇文章,讲了服务的注册和发现.在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于http restful的.Spring cloud有两种服务调用方式,一种是ribbon+r ...

  9. Python利用pandas处理数据后画图

    pandas要处理的数据是一个数据表格.代码: 1 import pandas as pd 2 import numpy as np 3 import matplotlib.pyplot as plt ...

  10. root密码忘记了,怎么办?

    root是管理员使用的超级用户,如果密码忘记了,可以使用以下两种方法修改. 方法一: 进入单用户模式下进行密码修改 步骤1:重启系统,在系统进入3秒启动阶段,快速点击键盘上任意键可以取消默认进入系统状 ...