idea中redis缓存与加密(MD5)

来源:互联网 发布:php程序员面试题 编辑:程序博客网 时间:2024/06/05 07:22

1,首先在电脑上安装Redis,安装步骤
(1),下载解压
(2),打开redis文件夹,按Shift+鼠标右键,打开小窗口输入命令
redis-server redis.windows.conf
(3),运行时先打开服务器,再开服务器

2,在pom.xml中添加依赖

<!-- redis -->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-data-redis</artifactId>        </dependency>    <!-- MD5加密-->        <dependency>            <groupId>com.github.ulisesbocchio</groupId>            <artifactId>jasypt-spring-boot-starter</artifactId>            <version>1.8</version>        </dependency>

3,在controller中引入模板

 //注入redis模板    @Autowired    private RedisTemplate redisTemplate;    //注入加密模板    @Autowired   private StringEncryptor stringEncryptor;

4,redis使用

@RequestMapping("/selectP")    public Person selectP(String pname){        Person p = null;        ValueOperations<String,Person> operations = redisTemplate.opsForValue();        Boolean exist = redisTemplate.hasKey("person");        if(exist){            p = operations.get("person");            System.out.print("已存在");        }else{            p = perDao.findByPname(pname);            operations.set("person",p);        }        return p;    }

代码说明 :会把查询结果存入redis中,如果有值,就不会去数据库查找(可以看控制台的hql语句输出,和响应时间)
5,MD5加密

#加密的算法jasypt.encryptor.password=123456spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/bootstrap_testspring.datasource.username=root#spring.datasource.password=rootspring.datasource.password=ENC(SgI8ZBeh0bT2tU65BwZuQw==)

首先在后台测试下

  @RequestMapping("/cs")    public String cs(){        String password = stringEncryptor.encrypt("123456");    //输出加密后的密码        System.out.print(password );        return result;    }

然后复制,替换掉原密码

判断配置文件是否正确 nginx -t
Mac下重启Nginx: nginx -s reload

原创粉丝点击