From 0feda333c54440129f0b329f179f27906e6ef02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=90=A6=E6=B6=9B?= Date: Thu, 9 Mar 2023 09:32:41 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=20sonar=E3=80=91DlMockController?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dlglong/controller/DlMockController.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/jero-boot/jero-boot-module-demo/src/main/java/com/jero/modules/dlglong/controller/DlMockController.java b/jero-boot/jero-boot-module-demo/src/main/java/com/jero/modules/dlglong/controller/DlMockController.java index 38db4787..8c831950 100644 --- a/jero-boot/jero-boot-module-demo/src/main/java/com/jero/modules/dlglong/controller/DlMockController.java +++ b/jero-boot/jero-boot-module-demo/src/main/java/com/jero/modules/dlglong/controller/DlMockController.java @@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.io.InputStream; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.*; @Slf4j @@ -142,7 +143,7 @@ public class DlMockController { */ @PutMapping("/immediateSaveRow") public Result mockImmediateSaveRow(@RequestBody JSONObject rowData) throws Exception { - System.out.println("即时保存.rowData:" + rowData.toJSONString()); + log.info("即时保存.rowData:" + rowData.toJSONString()); // 延时1.5秒,模拟网慢堵塞真实感 Thread.sleep(500); return Result.OK(); @@ -162,7 +163,7 @@ public class DlMockController { // 只传新增的数据给后台insert即可,否者将会造成性能上的浪费。 // 3、新增的行是没有id的,通过这一点,就可以判断是否是新增的数据 - System.out.println("即时保存.tableData:" + tableData.toJSONString()); + log.info("即时保存.tableData:" + tableData.toJSONString()); // 延时1.5秒,模拟网慢堵塞真实感 Thread.sleep(1000); return Result.OK(); @@ -220,30 +221,29 @@ public class DlMockController { // 获取查询条件(前台传递的查询参数) Map parameterMap = request.getParameterMap(); // 遍历输出到控制台 - System.out.println("\ngetDdjhData - 普通查询条件:"); + log.info("\ngetDdjhData - 普通查询条件:"); for (String key : parameterMap.keySet()) { - System.out.println("-- " + key + ": " + JSON.toJSONString(parameterMap.get(key))); + log.info("-- " + key + ": " + JSON.toJSONString(parameterMap.get(key))); } // 输出高级查询 try { - System.out.println("\ngetDdjhData - 高级查询条件:"); + log.info("\ngetDdjhData - 高级查询条件:"); // 高级查询模式 MatchTypeEnum matchType = MatchTypeEnum.getByValue(superQueryMatchType); if (matchType == null) { - System.out.println("-- 高级查询模式:不识别(" + superQueryMatchType + ")"); + log.info("-- 高级查询模式:不识别(" + superQueryMatchType + ")"); } else { - System.out.println("-- 高级查询模式:" + matchType.getValue()); + log.info("-- 高级查询模式:" + matchType.getValue()); } superQueryParams = URLDecoder.decode(superQueryParams, "UTF-8"); List conditions = JSON.parseArray(superQueryParams, QueryCondition.class); if (conditions != null) { for (QueryCondition condition : conditions) { - System.out.println("-- " + JSON.toJSONString(condition)); + log.info("-- " + JSON.toJSONString(condition)); } } else { - System.out.println("-- 没有传递任何高级查询条件"); + log.info("-- 没有传递任何高级查询条件"); } - System.out.println(); } catch (Exception e) { log.error("-- 高级查询操作失败:" + superQueryParams, e); e.printStackTrace(); @@ -255,7 +255,7 @@ public class DlMockController { // 封装成 MyBatisPlus 能识别的 QueryWrapper,可以直接使用这个对象进行SQL筛选条件拼接 // 这个方法也会自动封装高级查询条件,但是高级查询参数名必须是superQueryParams和superQueryMatchType QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(mockEntity, parameterMap); - System.out.println("queryWrapper: " + queryWrapper.getCustomSqlSegment()); + log.info("queryWrapper: " + queryWrapper.getCustomSqlSegment()); // 模拟JSON数据路径 String path = "classpath:com/jero/modules/dlglong/json/ddjh.json"; @@ -395,13 +395,13 @@ public class DlMockController { try { InputStream stream = getClass().getClassLoader().getResourceAsStream(path.replace("classpath:", "")); if (stream != null) { - String json = IOUtils.toString(stream, "UTF-8"); + String json = IOUtils.toString(stream, StandardCharsets.UTF_8); return JSON.parseArray(json); } } catch (IOException e) { log.error(e.getMessage(), e); } - return null; + return new JSONArray(); } }