首页>代码>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;
	}
}
最近下载更多
唐唐丶  LV33 2023年11月14日
西海岸之光  LV1 2022年12月30日
xiaoyuer2  LV8 2022年11月22日
飞梦ff  LV8 2021年9月17日
whfuai  LV14 2021年7月28日
shiopaaa  LV13 2021年3月9日
build138  LV20 2020年12月22日
lcl20181212  LV3 2020年11月28日
Xuan Minister  LV10 2020年9月17日
开心灬愉悦  LV9 2020年8月17日
最近浏览更多
唐唐丶  LV33 2023年11月14日
漫步的海星  LV4 2023年9月21日
woldxy  LV12 2023年8月22日
西海岸之光  LV1 2022年12月30日
JiangYing009  LV8 2022年12月29日
xiaoyuer2  LV8 2022年11月22日
周粥周  LV3 2022年10月12日
北斗闪耀星空 2022年5月9日
暂无贡献等级
shaojichun  LV4 2022年5月9日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友