From 2d3457690c42021db0829561f768c922195b60e5 Mon Sep 17 00:00:00 2001 From: tolag3 Date: Wed, 22 Jan 2025 17:56:45 +0900 Subject: [PATCH] =?UTF-8?q?=ED=86=B5=ED=95=A9=EA=B2=80=EC=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 개행 escape 오류 수정 --- src/main/java/seed/utils/FairnetUtils.java | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/seed/utils/FairnetUtils.java b/src/main/java/seed/utils/FairnetUtils.java index 57c9bf45..7cd2e6af 100644 --- a/src/main/java/seed/utils/FairnetUtils.java +++ b/src/main/java/seed/utils/FairnetUtils.java @@ -33,6 +33,7 @@ import javax.net.ssl.X509TrustManager; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; import org.springframework.ui.ModelMap; import org.springframework.web.client.RestTemplate; @@ -373,26 +374,32 @@ public class FairnetUtils { String url = new SearchGlobalSet().getHost() + "/srch_resultjson?" + "w=" + searchType - + "&q=" + searchKeyword + + "&q=" + "*" + searchKeyword + "*" + "&outmax=" + pagingSize + "§ion=" + "&pg=" + page; try { String response = new RestTemplate().getForObject(url, String.class); + response = response.replaceAll("\n", "\\n"); + response = response.replaceAll("\r", "\\r"); + JsonNode root = new ObjectMapper().readTree(response); JsonNode listNode = root.path("section_list") .path(0) .path("section") .path(0); - if (listNode.path("att_list").isArray()) { - List searchList = new ObjectMapper().convertValue( - listNode.path("att_list"), new TypeReference>() {} - ); - Map result = new HashMap(); - - result.put("totcnt", ((TextNode) listNode.get("totcnt")).asText()); - result.put("list", searchList); - return result; + if ( + listNode.path("att_list").isArray() + && !"\"\"".equals(listNode.path("att_list").get(0).toString()) + ) { + List searchList = new ObjectMapper().convertValue( + listNode.path("att_list"), new TypeReference>() {} + ); + Map result = new HashMap(); + + result.put("totcnt", ((TextNode) listNode.get("totcnt")).asText()); + result.put("list", searchList); + return result; } } catch (Exception e) { System.out.println(e.getMessage());