diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java index c09ba605cd..f0142f9750 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java @@ -16,7 +16,7 @@ public class ExtApiDefinitionExecResultProvider { .append("'") .append(result.getId()) .append("','") - .append(result.getName().replace("\'", "\\'")) + .append(translate(result.getName())) .append("','") .append(result.getResourceId()) .append("','") @@ -50,13 +50,9 @@ public class ExtApiDefinitionExecResultProvider { .append("','") .append(result.getEnvConfig()); //判断有没有关联的测试报告ID - if (StringUtils.isBlank(result.getRelevanceTestPlanReportId())) { - sqlList.append("', null"); - } else { - sqlList.append("','") - .append(result.getRelevanceTestPlanReportId()) - .append("'"); - } + sqlList.append("','") + .append(StringUtils.defaultIfBlank(result.getRelevanceTestPlanReportId(), "null")) + .append("'"); sqlList.append(")"); if (i < list.size() - 1) { sqlList.append(","); @@ -64,4 +60,12 @@ public class ExtApiDefinitionExecResultProvider { } return sqlList.toString(); } + + private String translate(String name) { + if (StringUtils.isNotBlank(name)) { + name = StringUtils.replace(name, "\'", "\\'"); + name = StringUtils.replace(name, "${", "$ {"); + } + return name; + } } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java index 2717018fd5..733472c725 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java @@ -18,7 +18,7 @@ public class ExtApiScenarioReportProvider { .append("','") .append(result.getProjectId()) .append("','") - .append(result.getName().replace("\'", "\\'")) + .append(translate(result.getName())) .append("',") .append(result.getCreateTime()) .append(",") @@ -32,7 +32,7 @@ public class ExtApiScenarioReportProvider { .append("','") .append(result.getExecuteType()) .append("','") - .append(result.getScenarioName().replace("\'", "\\'")) + .append(translate(result.getScenarioName())) .append("','") .append(result.getScenarioId()) .append("','") @@ -52,13 +52,9 @@ public class ExtApiScenarioReportProvider { .append("','") .append(result.getEnvConfig()); //判断有没有关联的测试报告ID - if (StringUtils.isBlank(result.getRelevanceTestPlanReportId())) { - sqlList.append("', null"); - } else { - sqlList.append("','") - .append(result.getRelevanceTestPlanReportId()) - .append("'"); - } + sqlList.append("','") + .append(StringUtils.defaultIfBlank(result.getRelevanceTestPlanReportId(), "null")) + .append("'"); sqlList.append(")"); if (i < list.size() - 1) { sqlList.append(","); @@ -66,4 +62,12 @@ public class ExtApiScenarioReportProvider { } return sqlList.toString(); } + + private String translate(String name) { + if (StringUtils.isNotBlank(name)) { + name = StringUtils.replace(name, "\'", "\\'"); + name = StringUtils.replace(name, "${", "$ {"); + } + return name; + } }