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
071beacc
Commit
071beacc
authored
Dec 15, 2020
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
79c922a4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
5 deletions
+54
-5
ExcelUtil.java
src/main/java/com/egolm/common/ExcelUtil.java
+31
-1
StringUtil.java
src/main/java/com/egolm/common/StringUtil.java
+1
-1
JdbcTemplate.java
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
+22
-3
No files found.
src/main/java/com/egolm/common/ExcelUtil.java
View file @
071beacc
...
...
@@ -8,7 +8,9 @@ import java.io.InputStream;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -30,7 +32,35 @@ import org.apache.poi.ss.usermodel.Row;
*/
public
class
ExcelUtil
{
/**
* 生成Excel
* @param os 输出流
* @param args 获取数据的键
* @param titles Excel表头
* @param widths Excel列宽度
* @param list 数据集
*/
public
static
void
excel
(
OutputStream
os
,
LinkedHashMap
<
String
,
String
>
titleMap
,
List
<
Map
<
String
,
Object
>>
list
)
{
List
<
String
>
argsList
=
new
ArrayList
<
String
>();
List
<
String
>
titleList
=
new
ArrayList
<
String
>();
for
(
String
key
:
titleMap
.
keySet
())
{
argsList
.
add
(
key
);
titleList
.
add
(
titleMap
.
get
(
key
));
}
String
[]
args
=
argsList
.
toArray
(
new
String
[
argsList
.
size
()]);
String
[]
titles
=
titleList
.
toArray
(
new
String
[
titleList
.
size
()]);
Object
[][]
objs
=
new
Object
[
list
.
size
()+
1
][
args
.
length
];
objs
[
0
]
=
titles
;
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Map
<
String
,
Object
>
map
=
list
.
get
(
i
);
Object
[]
obj
=
new
Object
[
args
.
length
];
for
(
int
k
=
0
;
k
<
obj
.
length
;
k
++)
{
obj
[
k
]
=
map
.
get
(
args
[
k
]);
}
objs
[
i
+
1
]
=
obj
;
}
ExcelUtil
.
excel
(
os
,
objs
,
null
);
}
/**
...
...
src/main/java/com/egolm/common/StringUtil.java
View file @
071beacc
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
View file @
071beacc
...
...
@@ -274,9 +274,28 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
}
public
int
save
(
String
tableName
,
Map
<
String
,
Object
>
objMap
)
{
Sql
desc
=
dialect
.
argsInsert
(
tableName
,
objMap
);
int
save_count
=
this
.
executeUpdate
(
desc
.
getSql
(),
desc
.
getArgs
());
return
save_count
;
Sql
iSql
=
dialect
.
argsInsert
(
tableName
,
objMap
);
KeyHolder
keyHolder
=
new
GeneratedKeyHolder
();
int
count
=
super
.
update
(
new
PreparedStatementCreator
()
{
public
PreparedStatement
createPreparedStatement
(
Connection
connection
)
throws
SQLException
{
PreparedStatement
ps
=
connection
.
prepareStatement
(
iSql
.
getSql
(),
Statement
.
RETURN_GENERATED_KEYS
);
Object
[]
args
=
iSql
.
getArgs
();
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
Object
argObj
=
args
[
i
];
if
(
argObj
instanceof
java
.
util
.
Date
)
{
java
.
util
.
Date
argDate
=
(
java
.
util
.
Date
)
argObj
;
ps
.
setObject
(
i
+
1
,
new
java
.
sql
.
Timestamp
(
argDate
.
getTime
()));
}
else
if
(
argObj
.
getClass
().
isEnum
())
{
ps
.
setObject
(
i
+
1
,
args
[
i
].
toString
());
}
else
{
ps
.
setObject
(
i
+
1
,
args
[
i
]);
}
}
return
ps
;
}
},
keyHolder
);
objMap
.
putAll
(
keyHolder
.
getKeys
());
return
count
;
}
public
int
delete
(
Object
...
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