Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
d11ca8a5
Commit
d11ca8a5
authored
May 09, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel导出功能
parent
729ff3b7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
16 deletions
+26
-16
BaseDaoSql.java
...db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
+26
-16
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
View file @
d11ca8a5
...
...
@@ -432,6 +432,31 @@ public abstract class BaseDaoSql {
return
sql
;
}
/**
* 处理代码片段替换
*
* @param sql 代码片段
* @param codeMap 替换内容
* @return Sql语句值
*/
protected
String
handleCodeRepalce
(
String
sql
,
Map
<
String
,
List
<
String
>>
codeMap
)
{
// 正则表达式匹配代码片段,并根据代码片段获取数组进行增加
String
regex
=
"\\{.*?\\}"
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
sql
);
// 寻找到的代码片段 不包含分括号
while
(
m
.
find
())
{
String
name
=
m
.
group
();
List
<
String
>
codes
=
codeMap
.
containsKey
(
name
)
?
codeMap
.
get
(
name
)
:
new
ArrayList
<>();
String
code
=
String
.
format
(
" %s "
,
String
.
join
(
" "
,
codes
));
sql
=
sql
.
replace
(
name
,
code
);
}
sql
=
sql
.
replaceAll
(
"\\s+"
,
"\\s"
);
return
sql
;
}
/**
* 代码片段处理
*
...
...
@@ -476,22 +501,7 @@ public abstract class BaseDaoSql {
}
}
// 正则表达式匹配代码片段,并根据代码片段获取数组进行增加
{
String
regex
=
"\\{.*?\\}"
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
sql
);
// 寻找到的代码片段 不包含分括号
while
(
m
.
find
())
{
String
name
=
m
.
group
();
List
<
String
>
codes
=
codeMap
.
containsKey
(
name
)
?
codeMap
.
get
(
name
)
:
new
ArrayList
<>();
String
code
=
String
.
format
(
" %s "
,
String
.
join
(
" "
,
codes
));
sql
=
sql
.
replace
(
name
,
code
);
}
}
sql
=
sql
.
replaceAll
(
"\\s+"
,
"\\s"
);
sql
=
handleCodeRepalce
(
sql
,
codeMap
);
return
sql
;
}
...
...
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