From 57dc41e1eff584fab674c9189e1b73b2fdee88e8 Mon Sep 17 00:00:00 2001 From: polarloves <1107061838@qq.com> Date: Wed, 19 Jul 2023 04:09:11 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=88=91=E4=B8=8D?= =?UTF-8?q?=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8=EF=BC=8C=E5=B0=B1=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: polarloves <1107061838@qq.com> --- Java/ThrowExceptionIsFoo.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Java/ThrowExceptionIsFoo.java diff --git a/Java/ThrowExceptionIsFoo.java b/Java/ThrowExceptionIsFoo.java new file mode 100644 index 0000000..2c0dce7 --- /dev/null +++ b/Java/ThrowExceptionIsFoo.java @@ -0,0 +1,19 @@ + @Cacheable(key = "#userId") + @Override + public List userResources(String userId) { + List resourceEntities = new ArrayList<>(); + // ... + JSONObject parseObject = JSONObject.parseObject(data); + if(parseObject.getInteger("code") == 200){ + List list = JSONObject.parseObject(JSONObject.toJSONString(parseObject.get("xxx")), List.class); + // CSK实例返回如何区分? + for (Object item: list) { + ResourceEntity resourceEntity = new ResourceEntity(); + JSONObject.parseObject(JSONObject.toJSONString(ckeCluster)); + item.setId(parseObject.getString("ckecluster_id")); + item.setName(parseObject.getString("cluster_name")); + resourceEntities.add(resourceEntity); + } + } + return resourceEntities; + } \ No newline at end of file -- Gitee From fb45febf186949c01545421e1d3a7bf0bb02c312 Mon Sep 17 00:00:00 2001 From: polarloves <1107061838@qq.com> Date: Wed, 19 Jul 2023 04:19:48 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8F=AA=E8=A6=81=E6=88=91=E4=B8=8D?= =?UTF-8?q?=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8=EF=BC=8C=E9=82=A3=E6=88=91?= =?UTF-8?q?=E5=B0=B1=E4=B8=8D=E4=BC=9A=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: polarloves <1107061838@qq.com> --- Java/ThrowExceptionIsFoo.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Java/ThrowExceptionIsFoo.java b/Java/ThrowExceptionIsFoo.java index 2c0dce7..88c7aeb 100644 --- a/Java/ThrowExceptionIsFoo.java +++ b/Java/ThrowExceptionIsFoo.java @@ -1,12 +1,14 @@ - @Cacheable(key = "#userId") + /** + * 业务需求:调用第三方接口,把结果存入缓存。 + */ + @Cacheable(key = "#userId") @Override public List userResources(String userId) { List resourceEntities = new ArrayList<>(); - // ... + // 调用第三方接口... JSONObject parseObject = JSONObject.parseObject(data); if(parseObject.getInteger("code") == 200){ List list = JSONObject.parseObject(JSONObject.toJSONString(parseObject.get("xxx")), List.class); - // CSK实例返回如何区分? for (Object item: list) { ResourceEntity resourceEntity = new ResourceEntity(); JSONObject.parseObject(JSONObject.toJSONString(ckeCluster)); @@ -15,5 +17,6 @@ resourceEntities.add(resourceEntity); } } + // 即使第三方接口出错了,我也不会抛出异常,数据虽然少了,但是我才不会有影响呢。 return resourceEntities; } \ No newline at end of file -- Gitee