diff --git a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java index 46bf748a9..d6b9a0c7b 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java @@ -27,7 +27,6 @@ import com.alibaba.nacos.config.server.service.PersistService; import com.alibaba.nacos.config.server.service.trace.ConfigTraceService; import com.alibaba.nacos.config.server.utils.*; import com.alibaba.nacos.config.server.utils.event.EventDispatcher; -import com.google.common.base.Joiner; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.slf4j.Logger; @@ -402,14 +401,14 @@ public class ConfigController { @ResponseBody public ResponseEntity exportConfig(HttpServletRequest request, HttpServletResponse response, - @RequestParam("group") String group, + @RequestParam(value = "dataId", required = false) String dataId, + @RequestParam(value = "group", required = false) String group, @RequestParam(value = "appName", required = false) String appName, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant, @RequestParam(value = "ids", required = false)List ids) { ids.removeAll(Collections.singleton(null)); - String idsStr = Joiner.on(",").join(ids); - List dataList = persistService.findAllConfigInfo4Export(group, tenant, appName, idsStr); + List dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids); List zipItemList = new ArrayList<>(); StringBuilder metaData = null; for(ConfigInfo ci : dataList){ @@ -544,8 +543,7 @@ public class ConfigController { } ids.removeAll(Collections.singleton(null)); - String idsStr = Joiner.on(",").join(ids); - List queryedDataList = persistService.findAllConfigInfo4Export(null, null, null, idsStr); + List queryedDataList = persistService.findAllConfigInfo4Export(null,null, null, null, ids); if(queryedDataList == null || queryedDataList.isEmpty()){ failedData.put("succCount", 0); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/PersistService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/PersistService.java index a3c64f8c7..786a51db8 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/PersistService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/PersistService.java @@ -3298,16 +3298,28 @@ public class PersistService { * @param group * @return Collection of ConfigInfo objects */ - public List findAllConfigInfo4Export(final String group, final String tenant, - final String appName, final String ids) { + public List findAllConfigInfo4Export(final String dataId, final String group, final String tenant, + final String appName, final List ids) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; StringBuilder where = new StringBuilder(" where "); - List paramList = new ArrayList<>(); - if(StringUtils.isNotBlank(ids)){ - where.append(" id in (").append(ids).append(") "); + List paramList = new ArrayList<>(); + if(!CollectionUtils.isEmpty(ids)){ + where.append(" id in ("); + for (int i = 0; i < ids.size(); i++) { + if (i != 0) { + where.append(", "); + } + where.append("?"); + paramList.add(ids.get(i)); + } + where.append(") "); } else { where.append(" tenant_id=? "); paramList.add(tenantTmp); + if (!StringUtils.isBlank(dataId)) { + where.append(" and data_id like ? "); + paramList.add(generateLikeArgument(dataId)); + } if (StringUtils.isNotBlank(group)) { where.append(" and group_id=? "); paramList.add(group); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/utils/ZipUtils.java b/config/src/main/java/com/alibaba/nacos/config/server/utils/ZipUtils.java index 6dc1766ac..b3ae92171 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/utils/ZipUtils.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/utils/ZipUtils.java @@ -115,7 +115,10 @@ public class ZipUtils { ZipItem metaDataItem = null; try (ZipInputStream zipIn = new ZipInputStream(new ByteArrayInputStream(source))) { ZipEntry entry; - while ((entry = zipIn.getNextEntry()) != null && !entry.isDirectory()) { + while ((entry = zipIn.getNextEntry()) != null) { + if(entry.isDirectory()){ + continue; + } try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { byte[] buffer = new byte[1024]; int offset;