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. STL algorithm算法lexicographical_compare(30)

    lexicographical_compare原型: std::lexicographical_compare default (1) template <class InputIterator ...

  2. arcserver开发小结(三)

    一.关于网络数据集的制作 由于要做实现网络分析的功能,而手中却没有网络数据集,关于网络数据集的制作,网上也有不少的资料.我参考的是ESRI为我们提供的帮助文档(Network_Analyst_Tuto ...

  3. 从 RNN 到 LSTM (Short-Term Memory)

    理论上循环神经网络可以支持任意长度的序列,然而在实际中,如果序列过长会导致优化时出现梯度消散(the vanishing gradient problem)的问题,在实际中一把会规定一个最大长度,当序 ...

  4. MVC HttpUtility.HtmlEncode是如何编码的

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;us ...

  5. Gradle离线配置

    原文:Gradle离线配置 1. 先在Gradle官网下载最新的离线zip压缩包. https://gradle.org/ 2. 将下载的zip压缩包,保存到本地磁盘下的目录中. 3. 修改(grad ...

  6. 利用WIX制作安装包(3)

    原文 利用WIX制作安装包(3) 利用WIX安装服务非常简单.只需要短短几句话就可以.当我们创建好一个Windows服务之后.我们在项目中创建一个Service.wxs 文件来安装服务,并且编辑代码如 ...

  7. erp的核心代码,替代orm

    public static SqlParameter[] get_array_list<T>(ArrayList rows) where T : class { Hashtable sql ...

  8. p批处理替换目录下文本中的字符串

    @echo off rem 进入批处理文件所在的路径 cd C:\Users\zxh\Desktop\ " as "abc" ***** rem 定义要替换的新旧字符串 ...

  9. GIS基础软件及操作(六)

    原文 GIS基础软件及操作(六) 练习六.空间分析的应用 1.加深对缓冲区分析基本原理.方法的认识:2.熟练掌握距离制图创建缓冲区技术方法.3.掌握利用缓冲区分析方法解决地学空间分析问题的能力. 1. ...

  10. 微信小程序把玩(九)scroll-view组件

    原文:微信小程序把玩(九)scroll-view组件 scroll-view为滚动视图,分为水平滚动和垂直滚动.注意滚动视图垂直滚动时一定要设置高度否则的话scroll-view不会生效.滚动视图常用 ...