Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
Overview
Overview
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
s_guodong
gjjs-bd-common
Commits
daab2c78
Commit
daab2c78
authored
Aug 24, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blok类型数据查询
parent
463bdd09
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
+79
-0
StringBlobTypeHandler.java
...brilliance/mda/support/mybatis/StringBlobTypeHandler.java
+79
-0
No files found.
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/StringBlobTypeHandler.java
0 → 100644
View file @
daab2c78
package
com
.
brilliance
.
mda
.
support
.
mybatis
;
import
org.apache.ibatis.type.BaseTypeHandler
;
import
org.apache.ibatis.type.JdbcType
;
import
org.apache.ibatis.type.MappedJdbcTypes
;
import
org.apache.ibatis.type.MappedTypes
;
import
org.springframework.stereotype.Component
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.sql.*
;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/24
*/
@MappedJdbcTypes
(
JdbcType
.
BLOB
)
@MappedTypes
(
String
.
class
)
@Component
public
class
StringBlobTypeHandler
extends
BaseTypeHandler
<
String
>
{
@Override
public
void
setNonNullParameter
(
PreparedStatement
ps
,
int
i
,
String
parameter
,
JdbcType
jdbcType
)
throws
SQLException
{
// 声明一个输入流对象
ByteArrayInputStream
bis
=
null
;
String
param
=
null
;
if
(
parameter
!=
null
)
{
//这里强转是因为知道了是String类型,可以看具体情况而定
param
=
parameter
;
}
try
{
// 把字符串转为字节流
bis
=
new
ByteArrayInputStream
(
param
.
getBytes
(
"utf-8"
));
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Blob Encoding Error!"
);
}
finally
{
if
(
bis
!=
null
)
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Blob Encoding Error!"
);
}
}
}
ps
.
setBinaryStream
(
i
,
bis
,
param
.
length
());
}
@Override
public
String
getNullableResult
(
ResultSet
rs
,
String
columnName
)
throws
SQLException
{
Blob
blob
=
rs
.
getBlob
(
columnName
);
String
returnValue
=
null
;
if
(
null
!=
blob
)
{
returnValue
=
new
String
(
blob
.
getBytes
(
1L
,
(
int
)
blob
.
length
()));
}
return
returnValue
;
}
@Override
public
String
getNullableResult
(
ResultSet
rs
,
int
columnIndex
)
throws
SQLException
{
Blob
blob
=
rs
.
getBlob
(
columnIndex
);
String
returnValue
=
null
;
if
(
null
!=
blob
)
{
returnValue
=
new
String
(
blob
.
getBytes
(
1L
,
(
int
)
blob
.
length
()));
}
return
returnValue
;
}
@Override
public
String
getNullableResult
(
CallableStatement
cs
,
int
columnIndex
)
throws
SQLException
{
Blob
blob
=
cs
.
getBlob
(
columnIndex
);
String
returnValue
=
null
;
if
(
null
!=
blob
)
{
returnValue
=
new
String
(
blob
.
getBytes
(
1L
,
(
int
)
blob
.
length
()));
}
return
returnValue
;
}
}
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