From 63c52fcc688063e03dc144da8be12b6fdae0360a Mon Sep 17 00:00:00 2001
From: chen-xin-zhi <3588068430@qq.com>
Date: Mon, 2 Dec 2024 08:30:57 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=95=86=E5=93=81?=
=?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 6 ++
.../book/impl/ClothesGradeServiceImpl.java | 2 +-
.../com/cultural/heritage/test/TestRedis.java | 22 +++++++
.../cultural/heritage/redis/JedisTest.java | 62 +++++++++++++++++++
.../cultural/heritage/redis/TestRedis.java | 32 ++++++++++
.../com/cultural/heritage/test/Hello.java | 23 +++++++
6 files changed, 146 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/com/cultural/heritage/test/TestRedis.java
create mode 100644 src/test/java/com/cultural/heritage/redis/JedisTest.java
create mode 100644 src/test/java/com/cultural/heritage/redis/TestRedis.java
create mode 100644 src/test/java/com/cultural/heritage/test/Hello.java
diff --git a/pom.xml b/pom.xml
index 44213f8..a5b8ea3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -171,6 +171,12 @@
true
+
+ redis.clients
+ jedis
+ 5.2.0
+
+
diff --git a/src/main/java/com/cultural/heritage/service/book/impl/ClothesGradeServiceImpl.java b/src/main/java/com/cultural/heritage/service/book/impl/ClothesGradeServiceImpl.java
index 1e09f60..f2ae087 100644
--- a/src/main/java/com/cultural/heritage/service/book/impl/ClothesGradeServiceImpl.java
+++ b/src/main/java/com/cultural/heritage/service/book/impl/ClothesGradeServiceImpl.java
@@ -49,7 +49,7 @@ public class ClothesGradeServiceImpl extends ServiceImpl= maxPrice.compareTo(BigDecimal.ZERO)) {
+ if (minPrice.compareTo(maxPrice) <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "最低价格不能高于最高价格");
}
if (StringUtils.isAnyBlank(clothesType, image, brief)) {
diff --git a/src/main/java/com/cultural/heritage/test/TestRedis.java b/src/main/java/com/cultural/heritage/test/TestRedis.java
new file mode 100644
index 0000000..f5af862
--- /dev/null
+++ b/src/main/java/com/cultural/heritage/test/TestRedis.java
@@ -0,0 +1,22 @@
+package com.cultural.heritage.test;
+
+//@Component
+//public class TestRedis {
+//
+// @Resource
+// private StringRedisTemplate stringRedisTemplate;
+//
+// @Resource
+// private GoodMapper goodMapper;
+//
+// @PostConstruct
+// public void test() {
+// List goodList = goodMapper.selectList(null);
+//
+// Map map = goodList.stream().collect(Collectors.toMap
+// (good -> good.getId().toString(), good -> good.getName()));
+// stringRedisTemplate.opsForHash().putAll("test", map);
+// stringRedisTemplate.opsForHash().get("test", "238");
+// }
+//
+//}
diff --git a/src/test/java/com/cultural/heritage/redis/JedisTest.java b/src/test/java/com/cultural/heritage/redis/JedisTest.java
new file mode 100644
index 0000000..5f3783d
--- /dev/null
+++ b/src/test/java/com/cultural/heritage/redis/JedisTest.java
@@ -0,0 +1,62 @@
+package com.cultural.heritage.redis;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class JedisTest {
+
+ private Jedis jedis;
+
+ /**
+ * 初始化Jedis实例
+ */
+ @Before
+ public void init() {
+ //指定Redis服务器的IP地址和端口号
+ jedis = new Jedis("127.0.0.1", 6379);
+ System.out.println("连接成功");
+ }
+
+ @Test
+ public void redisJedisTest() {
+ //操作字符串
+ //方法名与操作原生redis的命令一致
+ jedis.set("dec", "hello");
+ String dec = jedis.get("dec");
+ System.out.println(dec);
+
+ //操作list
+ jedis.lpush("data", "v1", "v2", "v3");
+ jedis.rpush("data", "v4", "v5", "v6");
+ List data = jedis.lrange("data", 0, -1);
+ for (String s : data) {
+ System.out.print(s + " ");
+ }
+ System.out.println();
+
+ //操作hash
+ HashMap hashMap = new HashMap<>();
+ hashMap.put("id", "1");
+ hashMap.put("name", "huhai");
+ hashMap.put("age", "24");
+ jedis.hset("object", hashMap);
+ Map object = jedis.hgetAll("object");
+ object.forEach((key, value) -> System.out.print(key + "=" + value + " "));
+ }
+
+ /**
+ * 关闭Jedis连接
+ */
+ @After
+ public void close() {
+ jedis.close();
+ System.out.println("连接已关闭");
+ }
+}
+
diff --git a/src/test/java/com/cultural/heritage/redis/TestRedis.java b/src/test/java/com/cultural/heritage/redis/TestRedis.java
new file mode 100644
index 0000000..ff12007
--- /dev/null
+++ b/src/test/java/com/cultural/heritage/redis/TestRedis.java
@@ -0,0 +1,32 @@
+package com.cultural.heritage.redis;
+
+import com.cultural.heritage.mapper.GoodMapper;
+import com.cultural.heritage.model.entity.Good;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Component
+public class TestRedis {
+
+ @Autowired
+ private StringRedisTemplate stringRedisTemplate;
+
+ @Autowired
+ private GoodMapper goodMapper;
+
+ @Test
+ public void test() {
+ List goodList = goodMapper.selectList(null);
+
+ Map map = goodList.stream().collect(Collectors.toMap
+ (good -> good.getId().toString(), good -> good.getName()));
+ stringRedisTemplate.opsForHash().putAll("test", map);
+ stringRedisTemplate.opsForHash().get("test", "238");
+ }
+}
diff --git a/src/test/java/com/cultural/heritage/test/Hello.java b/src/test/java/com/cultural/heritage/test/Hello.java
new file mode 100644
index 0000000..a57d474
--- /dev/null
+++ b/src/test/java/com/cultural/heritage/test/Hello.java
@@ -0,0 +1,23 @@
+package com.cultural.heritage.test;
+
+import java.math.BigDecimal;
+
+public class Hello {
+ public static void main(String[] args) {
+// Jedis jedis = new Jedis("localhost", 6379);
+// System.out.println("连接成功");
+// System.out.println("服务正在运行:" + jedis.ping());
+//
+// System.out.println(jedis.get("name"));
+// jedis.lpush("site-list", "Runoob");
+// jedis.lpush("site-list", "Google");
+// jedis.lpush("site-list", "Taobao");
+// List list = jedis.lrange("site-list", 0 ,2);
+// for(int i=0; i