一、缓存短信验证码
首先引入redis的启动依赖,然后打开redis,并在application.yml文件中配置redis的相关信息,就可以直接调用RedisTemplate对象了。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
redis:
host: 127.0.0.1
port: 6379
database: 0
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/18f3b47746af128d2ec88428ea701421.png)
package com.pan.reggie.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pan.reggie.common.R;
import com.pan.reggie.entity.User;
import com.pan.reggie.service.UserService;
import com.pan.reggie.utils.SMSUtils;
import com.pan.reggie.utils.ValidateCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;