springboot-redis-crda example

1. 从 https://github.com/XLuffyStory/springboot-redis-crdu 拿到源码之后,导入到STS Maven 项目

2.启动 redis-server

启动Springboot application

根据Controller 中的endpoint 测试 增删改查:

package com.redis.crdu;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; @RestController
public class CustomerResource { @Autowired
private CustomerRepository customerRepository; @RequestMapping("/save")
public Map<Long, Customer> save() {
// save a single Customer
customerRepository.save(new Customer(1, "Jack", "Smith"));
customerRepository.save(new Customer(2, "Adam", "Johnson"));
customerRepository.save(new Customer(3, "Kim", "Smith"));
customerRepository.save(new Customer(4, "David", "Williams"));
customerRepository.save(new Customer(5, "Peter", "Davis")); return customerRepository.findAll();
} @RequestMapping("/findall")
public String findAll() {
String result = "";
Map<Long, Customer> customers = customerRepository.findAll(); for (Customer customer : customers.values()) {
result += customer.toString() + "\n";
} return result;
} @RequestMapping("/find/{id}")
public String findById(@PathVariable( "id") Long id) {
String result = "";
if( customerRepository.findById(id) == null) {
return String.format("Can't find the specified Customer with ID as %s !", String.valueOf(id));
}
result = customerRepository.findById(id).toString();
return result;
} @RequestMapping(value = "/uppercase/{id}")
public String postCustomer(@PathVariable("id") Long id) {
Customer customer = customerRepository.findById(id);
customer.setFirstName(customer.getFirstName().toUpperCase());
customer.setLastName(customer.getLastName().toUpperCase()); customerRepository.update(customer);
return customerRepository.findById(id).toString(); // return "Done";
} @RequestMapping("/delete")
public String deleteById(@RequestParam("id") Long id) {
customerRepository.delete(id); return findAll();
}
}

Delete id as 2 and then find all 

springboot-redis-crda example的更多相关文章

  1. 补习系列(14)-springboot redis 整合-数据读写

    目录 一.简介 二.SpringBoot Redis 读写 A. 引入 spring-data-redis B. 序列化 C. 读写样例 三.方法级缓存 四.连接池 小结 一.简介 在 补习系列(A3 ...

  2. SpringBoot+Redis整合

    SpringBoot+Redis整合 1.在pom.xml添加Redis依赖 <!--整合Redis--> <dependency> <groupId>org.sp ...

  3. springboot +redis配置

    springboot +redis配置 pom依赖 <dependency> <groupId>org.springframework.boot</groupId> ...

  4. 【springboot】【redis】springboot+redis实现发布订阅功能,实现redis的消息队列的功能

    springboot+redis实现发布订阅功能,实现redis的消息队列的功能 参考:https://www.cnblogs.com/cx987514451/p/9529611.html 思考一个问 ...

  5. spring boot 学习(十四)SpringBoot+Redis+SpringSession缓存之实战

    SpringBoot + Redis +SpringSession 缓存之实战 前言 前几天,从师兄那儿了解到EhCache是进程内的缓存框架,虽然它已经提供了集群环境下的缓存同步策略,这种同步仍然需 ...

  6. SpringBoot + Redis:基本配置及使用

    注:本篇博客SpringBoot版本为2.1.5.RELEASE,SpringBoot1.0版本有些配置不适用 一.SpringBoot 配置Redis 1.1 pom 引入spring-boot-s ...

  7. 基于SpringBoot+Redis的Session共享与单点登录

    title: 基于SpringBoot+Redis的Session共享与单点登录 date: 2019-07-23 02:55:52 categories: 架构 author: mrzhou tag ...

  8. springboot + redis + 注解 + 拦截器 实现接口幂等性校验

    一.概念 幂等性, 通俗的说就是一个接口, 多次发起同一个请求, 必须保证操作只能执行一次 比如: 订单接口, 不能多次创建订单 支付接口, 重复支付同一笔订单只能扣一次钱 支付宝回调接口, 可能会多 ...

  9. Springboot + redis + 注解 + 拦截器来实现接口幂等性校验

    Springboot + redis + 注解 + 拦截器来实现接口幂等性校验   1. SpringBoot 整合篇 2. 手写一套迷你版HTTP服务器 3. 记住:永远不要在MySQL中使用UTF ...

  10. springboot+redis做事件过期通知业务

    springboot+redis做事件过期通知 博主也是初次体验,不足之处多多指教 我的业务场景 系统管理员要给维护员分配巡查路口设施的工作,由于路口比较多,管理员不知道哪些路口已经被分配了,况且过了 ...

随机推荐

  1. c#调用ffmpeg嵌入srt/ass字幕提示Unable to open xxx.srt......

    最近接触到c#调用ffmpeg嵌入srt/ass字幕,碰到一个错误困扰了很久 Unable to open xxx.srt Error initializing filter 'subtitles' ...

  2. [Swift]UIAlertController 以及 Swift 中的闭包和枚举

    原文地址:http://blog.callmewhy.com/2014/10/08/uialertcontroller-swift-closures-enum/ 在 iOS8 的 SDK 中, UIK ...

  3. Linux 下编译并安装配置 Qt 4.53全过程

    最近准备做 Nokia 的 Symbian,Maemo 下触摸屏开发.考虑到程序的跨平台可移植性,最终选择使用 Qt 开发.相对来说,国内关于 Qt 相关文档并不算很多.作者将 Linux 下编译并安 ...

  4. visual studio code 调试 .NET core 1.1.

    一  windows端  使用VsCode编写和调试.NET Core项目 1 .新建sln 解决方案 dotnet new sln -o slnname 2. 新建DLL 3.将DLL添加到sln: ...

  5. XF 主从页面

    using System; using Xamarin.Forms; using Xamarin.Forms.Xaml; [assembly: XamlCompilation (XamlCompila ...

  6. 利用最小二乘法拟合任意次函数曲线(C#)

    原文:利用最小二乘法拟合任意次函数曲线(C#) ///<summary>     ///用最小二乘法拟合二元多次曲线     ///</summary>     ///< ...

  7. C#热敏打印图片 串口打印图片

    原文:C#热敏打印图片 串口打印图片 如图,一步一步慢慢调出来的 //串口通信类 public System.IO.Ports.SerialPort serialPort = null; serial ...

  8. windows下服务程序相关(别人提供的5种封装使用)

    作者: daodaoliang 版本: V 0.0.1 日期: 2017年11月25日 1. Windows Service 编程实现 在windows平台下面编写 服务程序 免不了要去查看微软的开发 ...

  9. Android零基础入门第3节:带你一起来聊一聊Android开发环境

    原文:Android零基础入门第3节:带你一起来聊一聊Android开发环境 工欲善其事,必先利其器.Android开发人员在自己的计算机上编写和测试应用程序,然后将其部署到实际的设备上,那首先必不可 ...

  10. SignalR---服务端

    原文:SignalR---服务端 前段时间把SignalR的官网教程大致看了一下,算是翻译了一遍,加上了自己的个人理解, 一下上传三个文件,分别是服务端.web客户端.DOTNET客户端相关文档,供大 ...