Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
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
曲欣亮
common
Commits
172dc0ae
Commit
172dc0ae
authored
Jan 19, 2021
by
张永
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.linkfern.com/key/common.git
parents
fd4d8fc9
155976d8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
11 deletions
+38
-11
HttpUtil.java
src/main/java/com/egolm/common/HttpUtil.java
+7
-5
MathUtil.java
src/main/java/com/egolm/common/MathUtil.java
+5
-1
StringUtil.java
src/main/java/com/egolm/common/StringUtil.java
+13
-0
JdbcTemplate.java
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
+12
-4
Dialect.java
src/main/java/com/egolm/common/jdbc/dialect/Dialect.java
+1
-1
No files found.
src/main/java/com/egolm/common/HttpUtil.java
View file @
172dc0ae
...
@@ -298,8 +298,11 @@ public class HttpUtil {
...
@@ -298,8 +298,11 @@ public class HttpUtil {
return
StringUtil
.
join
(
"&"
,
params
);
return
StringUtil
.
join
(
"&"
,
params
);
}
}
public
static
String
post
(
String
requestUrl
,
Map
<
String
,
Object
>
parameters
,
Map
<
String
,
String
>
headers
,
public
static
String
post
(
String
requestUrl
,
Map
<
String
,
Object
>
parameters
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
File
>
attachments
)
{
Map
<
String
,
File
>
attachments
,
String
contentType
)
{
return
post
(
requestUrl
,
parameters
,
headers
,
attachments
,
"application/octet-stream"
);
}
public
static
String
post
(
String
requestUrl
,
Map
<
String
,
Object
>
parameters
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
File
>
attachments
,
String
contentType
)
{
HttpURLConnection
connection
=
null
;
HttpURLConnection
connection
=
null
;
try
{
try
{
Data
data
=
new
Data
();
Data
data
=
new
Data
();
...
@@ -320,9 +323,8 @@ public class HttpUtil {
...
@@ -320,9 +323,8 @@ public class HttpUtil {
StringBuffer
FileBuffer
=
new
StringBuffer
();
StringBuffer
FileBuffer
=
new
StringBuffer
();
File
file
=
attachments
.
get
(
name
);
File
file
=
attachments
.
get
(
name
);
FileBuffer
.
append
(
"--"
+
BOUNDARY
+
"\r\n"
);
FileBuffer
.
append
(
"--"
+
BOUNDARY
+
"\r\n"
);
FileBuffer
.
append
(
"Content-Disposition: form-data; name=\""
+
name
+
"\"; filename=\""
FileBuffer
.
append
(
"Content-Disposition: form-data; name=\""
+
name
+
"\"; filename=\""
+
file
.
getName
()
+
"\""
+
"\r\n"
);
+
file
.
getName
()
+
"\""
+
"\r\n"
);
FileBuffer
.
append
(
"Content-Type:"
+
contentType
+
"\r\n"
);
FileBuffer
.
append
(
"Content-Type:"
+
contentType
+
""
+
"\r\n"
);
FileBuffer
.
append
(
"\r\n"
);
FileBuffer
.
append
(
"\r\n"
);
String
FileBufferString
=
FileBuffer
.
toString
();
String
FileBufferString
=
FileBuffer
.
toString
();
data
.
add
(
FileBufferString
.
getBytes
());
data
.
add
(
FileBufferString
.
getBytes
());
...
...
src/main/java/com/egolm/common/MathUtil.java
View file @
172dc0ae
...
@@ -42,5 +42,9 @@ public class MathUtil {
...
@@ -42,5 +42,9 @@ public class MathUtil {
return
(
T
)
k
;
return
(
T
)
k
;
}
}
public
static
int
random
(
int
min
,
int
max
)
{
Random
random
=
new
Random
();
return
random
.
nextInt
(
max
)
%
(
max
-
min
+
1
)
+
min
;
}
}
}
src/main/java/com/egolm/common/StringUtil.java
View file @
172dc0ae
...
@@ -17,6 +17,7 @@ import java.util.Comparator;
...
@@ -17,6 +17,7 @@ import java.util.Comparator;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
java.util.TreeMap
;
import
java.util.TreeMap
;
import
java.util.UUID
;
import
java.util.UUID
;
...
@@ -53,6 +54,18 @@ import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombi
...
@@ -53,6 +54,18 @@ import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombi
*/
*/
public
class
StringUtil
{
public
class
StringUtil
{
private
static
final
String
str
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
public
static
String
getRandomString
(
int
length
){
Random
random
=
new
Random
();
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
length
;
i
++){
int
number
=
random
.
nextInt
(
62
);
sb
.
append
(
str
.
charAt
(
number
));
}
return
sb
.
toString
();
}
public
static
String
join
(
Map
<
String
,
Object
>
map
,
String
sign
,
String
before
,
String
after
,
String
joinKey
)
{
public
static
String
join
(
Map
<
String
,
Object
>
map
,
String
sign
,
String
before
,
String
after
,
String
joinKey
)
{
sign
=
sign
==
null
?
""
:
sign
;
sign
=
sign
==
null
?
""
:
sign
;
before
=
before
==
null
?
""
:
before
;
before
=
before
==
null
?
""
:
before
;
...
...
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
View file @
172dc0ae
...
@@ -543,15 +543,16 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
...
@@ -543,15 +543,16 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
});
});
}
}
public
List
<
Object
>
exec
(
final
String
sql
,
final
Object
...
args
)
{
public
List
<
Object
>
exec
(
final
String
sql
,
Object
...
args
)
{
showSql
(
sql
,
args
);
final
Object
[]
argsArray
=
this
.
toArray
(
args
);
showSql
(
sql
,
argsArray
);
Map
<
Integer
,
OutParameter
>
out
=
new
HashMap
<
Integer
,
OutParameter
>();
Map
<
Integer
,
OutParameter
>
out
=
new
HashMap
<
Integer
,
OutParameter
>();
return
super
.
execute
(
new
CallableStatementCreator
()
{
return
super
.
execute
(
new
CallableStatementCreator
()
{
public
CallableStatement
createCallableStatement
(
final
Connection
con
)
throws
SQLException
{
public
CallableStatement
createCallableStatement
(
final
Connection
con
)
throws
SQLException
{
final
CallableStatement
cs
=
con
.
prepareCall
(
sql
);
final
CallableStatement
cs
=
con
.
prepareCall
(
sql
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
args
Array
.
length
;
i
++)
{
Integer
index
=
i
+
1
;
Integer
index
=
i
+
1
;
Object
arg
=
args
[
i
];
Object
arg
=
args
Array
[
i
];
if
(
arg
!=
null
&&
arg
instanceof
OutParameter
)
{
if
(
arg
!=
null
&&
arg
instanceof
OutParameter
)
{
OutParameter
outArg
=
(
OutParameter
)
arg
;
OutParameter
outArg
=
(
OutParameter
)
arg
;
outArg
.
setValue
(
null
);
outArg
.
setValue
(
null
);
...
@@ -697,5 +698,12 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
...
@@ -697,5 +698,12 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
}
}
}
}
private
Object
[]
toArray
(
Object
...
args
)
{
while
(
args
!=
null
&&
args
.
length
==
1
&&
args
[
0
]
!=
null
&&
args
[
0
]
instanceof
Object
[])
{
args
=
(
Object
[])
args
[
0
];
}
return
args
;
}
}
}
src/main/java/com/egolm/common/jdbc/dialect/Dialect.java
View file @
172dc0ae
...
@@ -247,7 +247,7 @@ public interface Dialect {
...
@@ -247,7 +247,7 @@ public interface Dialect {
}
}
objs
[
i
]
=
objArg
;
objs
[
i
]
=
objArg
;
}
}
String
sql
=
"delete from "
+
tableName
+
StringUtil
.
join
(
" and "
,
" where "
,
""
,
args
);
String
sql
=
"delete from "
+
tableName
+
StringUtil
.
join
(
" and "
,
" where "
,
""
,
args
);
return
new
Sql
(
sql
,
objs
);
return
new
Sql
(
sql
,
objs
);
}
}
...
...
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