idea中redis缓存与加密(MD5)

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

2,在pom.xml中添加依赖


        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-redisartifactId>
        dependency>
    
        <dependency>
            <groupId>com.github.ulisesbocchiogroupId>
            <artifactId>jasypt-spring-boot-starterartifactId>
            <version>1.8version>
        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 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=123456


spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/bootstrap_test
spring.datasource.username=root
#spring.datasource.password=root

spring.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

你可能感兴趣的:(加密)