Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a5f112f4
authored
Feb 29, 2024
by
龚榕城
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
模版替换方法
parent
33797db1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletions
server-service/src/main/java/com/makeit/service/platform/alarm/impl/PlatAlarmRecordServiceImpl.java
server-service/src/main/java/com/makeit/service/platform/alarm/impl/PlatAlarmRecordServiceImpl.java
View file @
a5f112f4
...
@@ -635,7 +635,7 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
...
@@ -635,7 +635,7 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
}
}
public
static
String
replaceParam
(
String
oriContent
,
List
<
String
>
param
)
{
public
static
String
replaceParam
(
String
oriContent
,
List
<
String
>
param
)
{
Pattern
p
=
Pattern
.
compile
(
"\\[#\\d+\\]|\\[#[\\p{IsHan}]+\\]|\\[#[^\\]]*\\]"
);
/*
Pattern p = Pattern.compile("\\[#\\d+\\]|\\[#[\\p{IsHan}]+\\]|\\[#[^\\]]*\\]");
Matcher m = p.matcher(oriContent);
Matcher m = p.matcher(oriContent);
StringBuffer sb = new StringBuffer();
StringBuffer sb = new StringBuffer();
if (!m.find()) {
if (!m.find()) {
...
@@ -652,6 +652,30 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
...
@@ -652,6 +652,30 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
i++;
i++;
}
}
m.appendTail(sb);
m.appendTail(sb);
return sb.toString();*/
Pattern
pattern
=
Pattern
.
compile
(
"\\[#(.*?)\\]"
);
Matcher
matcher
=
pattern
.
matcher
(
oriContent
);
int
placeholderCount
=
0
;
while
(
matcher
.
find
())
{
placeholderCount
++;
}
if
(
param
.
size
()
>
placeholderCount
)
{
param
=
new
LinkedList
<>(
param
).
subList
(
param
.
size
()
-
placeholderCount
,
param
.
size
());
}
matcher
.
reset
();
StringBuffer
sb
=
new
StringBuffer
();
int
i
=
0
;
while
(
matcher
.
find
())
{
String
replacement
=
i
<
param
.
size
()
?
param
.
get
(
i
)
:
""
;
matcher
.
appendReplacement
(
sb
,
replacement
);
i
++;
}
matcher
.
appendTail
(
sb
);
return
sb
.
toString
();
return
sb
.
toString
();
}
}
...
...
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