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