所需依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
1、存入cookie中的方式:
Cookie cookie = new Cookie(“sign”, newToken);
cookie.setMaxAge(3600);
cookie.setPath("/");
cookie.setHttpOnly(true);
response.addCookie(cookie);
销毁cookie:
Cookie cookie2 = new Cookie(“sign”, null);
cookie2.setMaxAge(0);
cookie2.setPath("/");
cookie2.setHttpOnly(true);
response.addCookie(cookie2);
2、存入redis中的方式:
redisTemplate.opsForValue.set(userId + “:token”, value, 18000);
***获取redis中存储信息的过期时间:* **
redisTemplate.getExpire(key,TimeUnit.SECONDS);
销毁redis中的token:
redisTemplate.expire(“key”,time,TimeUnit.SECONDS);