ssm整合redis

ssm整合redisTemplete

1,引入坐标(版本一定要对的上,不然就可能出现错误)

    
      redis.clients
      jedis
      2.4.2
    
    
      org.springframework.data
      spring-data-redis
      1.3.0.RELEASE
    

2,redis.properties

redis.host=192.168.240.135
redis.port=6379
redis.password=***
redis.timeout=100000
redis.maxTotal=300
redis.maxIdle=200
redis.maxWait=10000
redis.testOnBorrow=true
redis.testOnReturn=true

# 默认缓存失效时间
defaultCacheExpireTime=3600

3,springRedis.xml



    
    
    
    
        
        
        
        
        
    
    
    
    




    
        
        
        
            
            
        
        
        
            
        
        
        
            
        
        
        
            
        
    


3,引入到主applicationContext.xml

    
    

4,测试

4.1 Controller 添加一段代码

@Controller
@ResponseBody
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {
    @Autowired
    AdminService adminService;
    @Autowired
    JWTUtils jwt;
    @Autowired
    RedisTemplate redisTemplate;
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    DataReturn login(@RequestBody Admin admin) {
        redisTemplate.opsForValue().append("teskinfly","handsome");//在这里测试
        if (!adminService.checkPwd(admin.getAName(), admin.getAPwd()))
            return new DataReturn(ReturnCode.FAIL);
        Admin byName = adminService.findByName(admin.getAName());
        String s = jwt.create(byName.getAId(), byName.getAName());
        return new DataReturn(ReturnCode.SUCCESS, s);
    }
}

4.2 用postman发送请求


image.png

4.3 查看redis,已经存进去


image.png

你可能感兴趣的:(ssm整合redis)