diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java index 55aaf12..2b9b50c 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java @@ -161,7 +161,10 @@ public class RehearsalRecordServiceImpl extends ServiceImpl iterator = p.getRuns().iterator(); - while (iterator.hasNext()) { - XWPFRun r = iterator.next(); - String text = r.getText(0); + for (int index = 0; index < p.getRuns().size(); index++) { + XWPFRun run = p.getRuns().get(index); + String text = run.getText(0); if (findText.equals(text)) { - r.setText("", 0); // 清除原有文本 - XWPFParagraph paragraph = r.getParagraph(); + run.setText("", 0); // 清除原有文本 + XWPFParagraph paragraph = run.getParagraph(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String name = jsonObject.getString("name"); String url = jsonObject.getString("url"); - url = URLEncoder.encode(url, "UTF-8"); - String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId(); + // url编码格式化 + String encodeName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20"); + String prefixString = url.substring(0, url.lastIndexOf("/") + 1); + String encodeUrl = prefixString + encodeName; + String id = paragraph.getDocument().getPackagePart().addExternalRelationship(encodeUrl, + XWPFRelation.HYPERLINK.getRelation()).getId(); CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); cLink.setId(id); CTText ctText = CTText.Factory.newInstance(); @@ -148,7 +151,7 @@ public class BaseUtil { CTR ctr = CTR.Factory.newInstance(); ctr.setTArray(new CTText[]{ctText}); cLink.setRArray(new CTR[]{ctr}); - if (i