From ba78098747184532dda0de21d72ffaba8054440a Mon Sep 17 00:00:00 2001 From: ronger Date: Tue, 2 Aug 2022 08:14:34 +0800 Subject: [PATCH 1/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e9628a..bee171d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ forest([ˈfôrəst],n.森林)是一款现代化的知识社区项目,使 ## ⚡ 动机 -在 2019 年的某一天,受到 [Hugh](https://rymcu.com/user/RYMCU-J) 的邀请, 构建一个开源嵌入式知识学习交流平台。因此就有了 forest 这个项目。 forest +在 2019 年的某一天,受到 [Hugh](https://rymcu.com/user/Hugh) 的邀请, 构建一个开源嵌入式知识学习交流平台。因此就有了 forest 这个项目。 forest 在很多方面受到了 [Symphony](https://github.com/88250/symphony) 的启发,并尝试着在 [Symphony](https://github.com/88250/symphony) 和 [B3log 思想](https://ld246.com/article/1546941897596) 的基础上进一步探索。 @@ -96,4 +96,4 @@ forest([ˈfôrəst],n.森林)是一款现代化的知识社区项目,使 ## 鸣谢 - 感谢 `JetBrains` 对本项目的帮助,为作者提供了开源许可版 `JetBrains` 全家桶 -![JetBrains](src/main/resources/static/jetbrains.png) \ No newline at end of file +![JetBrains](src/main/resources/static/jetbrains.png) From 869d881f8164f04010afb4d93f04369b390faf43 Mon Sep 17 00:00:00 2001 From: ronger Date: Sat, 3 Sep 2022 16:30:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:bug:=20StackOverflowError=20=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/service/impl/TagServiceImpl.java | 13 +- .../com/rymcu/forest/util/CacheUtils.java | 135 ------------------ 2 files changed, 9 insertions(+), 139 deletions(-) delete mode 100644 src/main/java/com/rymcu/forest/util/CacheUtils.java diff --git a/src/main/java/com/rymcu/forest/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/TagServiceImpl.java index 25fcf3f..ce37474 100644 --- a/src/main/java/com/rymcu/forest/service/impl/TagServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/TagServiceImpl.java @@ -1,8 +1,11 @@ package com.rymcu.forest.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.rymcu.forest.core.exception.BusinessException; import com.rymcu.forest.core.exception.ServiceException; import com.rymcu.forest.core.service.AbstractService; +import com.rymcu.forest.core.service.redis.RedisService; import com.rymcu.forest.dto.ArticleTagDTO; import com.rymcu.forest.dto.LabelModel; import com.rymcu.forest.entity.Article; @@ -10,7 +13,6 @@ import com.rymcu.forest.entity.Tag; import com.rymcu.forest.mapper.ArticleMapper; import com.rymcu.forest.mapper.TagMapper; import com.rymcu.forest.service.TagService; -import com.rymcu.forest.util.CacheUtils; import com.rymcu.forest.util.XssUtils; import com.rymcu.forest.web.api.common.UploadController; import com.rymcu.forest.web.api.exception.BaseApiException; @@ -35,6 +37,8 @@ public class TagServiceImpl extends AbstractService implements TagService { private TagMapper tagMapper; @Resource private ArticleMapper articleMapper; + @Resource + private RedisService redisService; @Override @Transactional(rollbackFor = {UnsupportedEncodingException.class, BaseApiException.class}) @@ -63,7 +67,7 @@ public class TagServiceImpl extends AbstractService implements TagService { int n = articleTagDTOList.size(); for (int m = 0; m < n; m++) { ArticleTagDTO articleTag = articleTagDTOList.get(m); - if (articleTag.getIdTag().equals(tag.getIdTag())) { + if (articleTag.getIdTag().toString().equals(tag.getIdTag().toString())) { articleTagDTOList.remove(articleTag); m--; n--; @@ -93,6 +97,7 @@ public class TagServiceImpl extends AbstractService implements TagService { return 1; } else { if (StringUtils.isNotBlank(articleContentHtml)) { + article.setArticleTags("待分类"); saveTagArticle(article, articleContentHtml, userId); } } @@ -152,10 +157,10 @@ public class TagServiceImpl extends AbstractService implements TagService { @Override public List findTagLabels() { - List list = (List) CacheUtils.get("tags"); + List list = JSONObject.parseArray(redisService.get("tags"), LabelModel.class); if (list == null) { list = tagMapper.selectTagLabels(); - CacheUtils.put("tags", list); + redisService.set("tags", JSON.toJSONString(list), 600); } return list; } diff --git a/src/main/java/com/rymcu/forest/util/CacheUtils.java b/src/main/java/com/rymcu/forest/util/CacheUtils.java deleted file mode 100644 index bac94a2..0000000 --- a/src/main/java/com/rymcu/forest/util/CacheUtils.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.rymcu.forest.util; - -import org.apache.shiro.cache.Cache; -import org.apache.shiro.cache.CacheManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Set; - -/** - * Cache工具类 - */ -public class CacheUtils { - - private static final Logger LOGGER = LoggerFactory.getLogger(CacheUtils.class); - private static final CacheManager CACHE_MANAGER = SpringContextHolder.getBean(CacheManager.class); - - private static final String SYS_CACHE = "system"; - - /** - * 获取SYS_CACHE缓存 - * @param key 键值 - * @return 缓存对象 - */ - public static Object get(String key) { - return get(SYS_CACHE, key); - } - - /** - * 获取SYS_CACHE缓存 - * @param key 键值 - * @param defaultValue 默认返回值 - * @return 缓存对象或默认值 - */ - public static Object get(String key, Object defaultValue) { - Object value = get(key); - return value != null ? value : defaultValue; - } - - /** - * 写入SYS_CACHE缓存 - * @param key 键值 - * @param value 被缓存对象 - */ - public static void put(String key, Object value) { - put(SYS_CACHE, key, value); - } - - /** - * 从SYS_CACHE缓存中移除 - * @param key 键值 - */ - public static void remove(String key) { - remove(SYS_CACHE, key); - } - - /** - * 获取指定命名空间下的缓存 - * @param cacheName 缓存命名空间 - * @param key 键值 - * @return 该命名空间下的对应键值缓存 - */ - public static Object get(String cacheName, String key) { - return getCache(cacheName).get(getKey(key)); - } - - /** - * 获取指定命名空间下的缓存,并在无缓存对象时返回默认值 - * @param cacheName 缓存命名空间 - * @param key 键值 - * @param defaultValue 默认返回值 - * @return 缓存对象或默认值 - */ - public static Object get(String cacheName, String key, Object defaultValue) { - Object value = get(cacheName, getKey(key)); - return value != null ? value : defaultValue; - } - - /** - * 向指定命名空间下存入被缓存对象 - * @param cacheName 缓存命名空间 - * @param key 键值 - * @param value 该命名空间下被缓存对象 - */ - public static void put(String cacheName, String key, Object value) { - getCache(cacheName).put(getKey(key), value); - } - - /** - * 将指定命名空间下的缓存移除 - * @param cacheName 缓存命名空间 - * @param key 键值 - */ - public static void remove(String cacheName, String key) { - getCache(cacheName).remove(getKey(key)); - } - - /** - * 清空命名空间下所有缓存 - * @param cacheName 命名空间 - */ - public static void removeAll(String cacheName) { - Cache cache = getCache(cacheName); - Set keys = cache.keys(); - cache.clear(); - LOGGER.info("清理缓存: {} => {}", cacheName, keys); - } - - /** - * 获取缓存键名,多数据源下增加数据源名称前缀 - * @param key 键值 - * @return 返回对应数据源前缀拼接键值 - */ - private static String getKey(String key){ -// String dsName = DataSourceHolder.getDataSourceName(); -// if (StringUtils.isNotBlank(dsName)){ -// return dsName + "_" + key; -// } - return key; - } - - /** - * 获得指定命名空间的Cache,没有则显示日志。 - * @param cacheName 命名空间 - * @return 命名空间对应的Cache - */ - private static Cache getCache(String cacheName){ - Cache cache = CACHE_MANAGER.getCache(cacheName); - if (cache == null){ - throw new RuntimeException("当前系统中没有定义“"+cacheName+"”这个缓存。"); - } - return cache; - } - -}