From 29bd9953e17d308cc45e443f3b3ac740332fb276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=89=B4=E5=AE=A2?= Date: Tue, 28 May 2019 16:41:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=B9=E5=88=AB=E5=95=B0=E5=97=A6=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E6=9C=AC=E6=9D=A5=E5=8F=AF=E5=87=89?= =?UTF-8?q?=E4=B8=89=E4=BA=94=E8=A1=8C=E4=BB=A3=E7=A0=81=E5=B0=B1=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=90=9E=E5=AE=9A=E4=BA=86=EF=BC=8C=E5=86=99=E4=BA=86?= =?UTF-8?q?=E5=8D=81=E5=87=A0=E4=BA=8C=E5=8D=81=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java/CheckExist.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 java/CheckExist.java diff --git a/java/CheckExist.java b/java/CheckExist.java new file mode 100644 index 0000000..e03cea4 --- /dev/null +++ b/java/CheckExist.java @@ -0,0 +1,28 @@ +/** + * 是否收藏(有没有感觉这段代码特别特别啰嗦,不够简洁) + * @param articleKey + * @param user + * @return + */ +public boolean isFavorite(String articleKey, User user) { + boolean isFavorite = false; + if (user == null) { + return false; + } + long userId = user.getId(); + Article article = getByArticleKey(articleKey); + if (null == article) { + return false; + } + List list = listAttentionUsers(article); + if (list == null || list.size() <= 0) { + return false; + } + for (Long id : list) { + if (id == userId) { + isFavorite = true; + break; + } + } + return isFavorite; +} -- Gitee