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
b96db6b2
Commit
b96db6b2
authored
Sep 15, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
c1063d50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
8 deletions
+19
-8
DbPrintSql.java
...-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
+8
-8
TestDbPrintSql.java
yzg-util-db/src/test/java/TestDbPrintSql.java
+11
-0
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
View file @
b96db6b2
...
@@ -27,11 +27,15 @@ public class DbPrintSql {
...
@@ -27,11 +27,15 @@ public class DbPrintSql {
public
String
getStringSql
(
String
sql
,
Object
...
paras
)
{
public
String
getStringSql
(
String
sql
,
Object
...
paras
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
String
[]
split
=
sql
.
split
(
"\\?"
);
String
[]
split
=
sql
.
split
(
"\\?"
);
int
pos
=
0
;
int
pos
=
0
;
while
(
pos
<
split
.
length
)
{
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
sb
.
append
(
split
[
pos
]);
for
(
Object
item
:
paras
)
{
if
(
pos
==
split
.
length
-
1
)
{
break
;
}
Object
item
=
paras
.
length
>
pos
?
paras
[
pos
]
:
null
;
String
str
=
StringHelper
.
toString
(
item
);
String
str
=
StringHelper
.
toString
(
item
);
String
strTo
=
str
;
String
strTo
=
str
;
if
(
str
==
null
)
{
if
(
str
==
null
)
{
...
@@ -41,15 +45,11 @@ public class DbPrintSql {
...
@@ -41,15 +45,11 @@ public class DbPrintSql {
}
else
{
}
else
{
strTo
=
"'"
+
str
.
replace
(
"'"
,
"''"
)
+
"'"
;
strTo
=
"'"
+
str
.
replace
(
"'"
,
"''"
)
+
"'"
;
}
}
sb
.
append
(
split
[
pos
]);
pos
++;
sb
.
append
(
strTo
);
sb
.
append
(
strTo
);
}
while
(
pos
<
split
.
length
)
{
sb
.
append
(
split
[
pos
]);
pos
++;
pos
++;
}
}
return
sb
.
toString
();
return
sb
.
toString
();
}
}
...
...
yzg-util-db/src/test/java/TestDbPrintSql.java
0 → 100644
View file @
b96db6b2
import
com.yanzuoguang.db.impl.DbPrintSql
;
import
org.junit.Test
;
public
class
TestDbPrintSql
{
@Test
public
void
test
(){
DbPrintSql
printSql
=
new
DbPrintSql
();
String
stringSql
=
printSql
.
getStringSql
(
"select * from where id = ? AND name = ? and removeFlag = 0 "
,
"1"
);
System
.
out
.
println
(
stringSql
);
}
}
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