Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
5b6c6498
Commit
5b6c6498
authored
May 24, 2024
by
韩桐桐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(jg):模板填充字段特殊字符转义
parent
12a84b09
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
1 deletion
+31
-1
WordTemplateUtils.java
...join/amos/boot/module/jg/biz/utils/WordTemplateUtils.java
+31
-1
No files found.
amos-boot-system-tzs/amos-boot-module-jg/amos-boot-module-jg-biz/src/main/java/com/yeejoin/amos/boot/module/jg/biz/utils/WordTemplateUtils.java
View file @
5b6c6498
...
...
@@ -63,7 +63,7 @@ public class WordTemplateUtils {
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer
writer
=
new
OutputStreamWriter
(
Files
.
newOutputStream
(
docFile
.
toPath
()),
StandardCharsets
.
UTF_8
)
)
{
template
.
process
(
dataMap
,
writer
);
template
.
process
(
escapeSpecialCharacters
(
dataMap
)
,
writer
);
}
return
docFile
;
}
...
...
@@ -226,4 +226,34 @@ public class WordTemplateUtils {
return
instance
.
fillAndConvertDocFile
(
wordPath
,
pdfName
,
placeholders
,
SaveFormat
.
PDF
);
}
/**
* 下载填充模板的字段,特殊符号转义
*/
private
static
Map
<
String
,
Object
>
escapeSpecialCharacters
(
Map
<
String
,
?>
inputMap
)
{
Map
<
String
,
Object
>
escapedMap
=
new
HashMap
<>();
for
(
Map
.
Entry
<
String
,
?>
entry
:
inputMap
.
entrySet
())
{
String
key
=
entry
.
getKey
();
Object
value
=
entry
.
getValue
();
if
(
value
instanceof
String
)
{
escapedMap
.
put
(
key
,
escapeValue
((
String
)
value
));
}
else
if
(
value
instanceof
Map
)
{
escapedMap
.
put
(
key
,
escapeSpecialCharacters
((
Map
<
String
,
Object
>)
value
));
}
else
{
escapedMap
.
put
(
key
,
value
);
}
}
return
escapedMap
;
}
private
static
String
escapeValue
(
String
value
)
{
if
(
value
==
null
)
{
return
null
;
}
return
value
.
replace
(
"&"
,
"&"
)
.
replace
(
"<"
,
"<"
)
.
replace
(
">"
,
">"
)
.
replace
(
"\""
,
"""
)
.
replace
(
"'"
,
"'"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment