[Wise] Springboot school operating one of Redis

Here Insert Picture Description
Here Insert Picture Description
beigin,use springboot,select name from IE;
Here Insert Picture Description
if we want to set,as this:
Here Insert Picture Description
Here Insert Picture Description
Now,let us start。
Here Insert Picture Description
application.properties:

server.port=8085
spring.application.name=redis-server

Controller:

package com.huizhi.demoredis2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controller {

    @Autowired
    private StringRedisTemplate template;

    @RequestMapping("/redis/get/{key}")
    private String get(@PathVariable("key") String key){
        return template.opsForValue().get(key);
    }

    @RequestMapping("/redis/set/{key}/{value}")
    private Boolean set(@PathVariable("key") String key,@PathVariable("value") String value){
        boolean flag = true;
        try {
            template.opsForValue().set(key,value);
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
        return flag;
    }

}

Demoredis2Application:

package com.huizhi.demoredis2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Demoredis2Application {

    public static void main(String[] args) {
        SpringApplication.run(Demoredis2Application.class, args);
    }
}

dependency

<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>
Published 268 original articles · won praise 47 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_39593940/article/details/103840024