原來的代碼:
jdbcTemplate
.
update
(
"INSERT INTO net_uploadcont (id, content, busiid) VALUES (?, ?, ?)"
,
netUploadcont
.
getId
(),
netUploadcont
.
getContent
(),
netUploadcont
.
getBusiid
());
修改後的代碼
@
Override
public
void
insert
(
NetUploadcont
netUploadcont
) {
String
sql
=
"INSERT INTO net_uploadcont (id,content,busiid)VALUES(?, ?,?)"
;
jdbcTemplate
.
execute
(
sql
, (
PreparedStatementCallback
<
Integer
>
)
preparedStatement
->
{
{
// 設置ID
preparedStatement
.
setLong
(
1
,
netUploadcont
.
getId
());
byte
[]
bytes
=
netUploadcont
.
getContent
().
getBytes
(
1
, (
int
)
netUploadcont
.
getContent
().
length
());
preparedStatement
.
setBinaryStream
(
2
,
new
ByteArrayInputStream
(
bytes
),
bytes
.
length
);
preparedStatement
.
setLong
(
3
,
netUploadcont
.
getBusiid
());
// 執行更新
preparedStatement
.
executeUpdate
();
}
return
1
;
// 返回插入的記錄數
});
}