首页>代码>SpringBoot2.1.4整合Redis、Jedis通过注解形式,进行简单的字符串数据类型的增删改查>/springboot-redis/src/main/java/com/example/demo/controller/TestController.java
package com.example.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.entity.Test;
import com.example.demo.service.TestService;
/**
* 调用service进行redis的CRUD
* @author 程就人生
* @date 2019年11月5日
*/
@RestController
public class TestController {
@Autowired
private TestService testService;
//新增
@GetMapping("/add")
public Test add(){
Test test = new Test();
test.setUid("123");
test.setUsername("aa");
testService.add(test);
System.out.println("新增操作:"+test.toString());
return test;
}
//删除
@GetMapping("/del")
public void del(){
testService.del("123");
System.out.println("删除操作:123");
}
//修改
@GetMapping("/update")
public Test update(){
Test test = new Test();
test.setUid("123");
test.setUsername("aaaaabbbbbb");
testService.update(test);
System.out.println("修改操作:"+test.toString());
return test;
}
//查询
@GetMapping("/retrieve")
public Test retrieve(){
Test test = testService.retrieve("123");
if(test != null){
System.out.println("查询结果:" + test.toString());
}else{
System.out.println("查询结果:数据123不存在!");
}
return test;
}
}
最近下载更多

最近浏览