Browse Source

fix: 超链接url添加格式化编码

zhongwei
liwen 7 months ago
parent
commit
e110226ca8
  1. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

7
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

@ -138,7 +138,12 @@ public class BaseUtil {
JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name"); String name = jsonObject.getString("name");
String url = jsonObject.getString("url"); String url = jsonObject.getString("url");
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(); CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id); cLink.setId(id);
CTText ctText = CTText.Factory.newInstance(); CTText ctText = CTText.Factory.newInstance();

Loading…
Cancel
Save