7 changed files with 90 additions and 17 deletions
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
package com.cloud.kicc.system.api.devtools.handler; |
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler; |
||||
import org.apache.ibatis.type.JdbcType; |
||||
|
||||
import java.io.ByteArrayInputStream; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.sql.*; |
||||
|
||||
/** |
||||
*<p> |
||||
* BlobToString 字段类型转换 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @Since: 2024/2/27 |
||||
*/ |
||||
public class BlobToStringTypeHandler extends BaseTypeHandler<String> { |
||||
|
||||
@Override |
||||
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { |
||||
ByteArrayInputStream bis = new ByteArrayInputStream(parameter.getBytes(StandardCharsets.UTF_8)); |
||||
ps.setBinaryStream(i, bis, parameter.getBytes().length); |
||||
} |
||||
|
||||
@Override |
||||
public String getNullableResult(ResultSet rs, String columnName) throws SQLException { |
||||
Blob blob = rs.getBlob(columnName); |
||||
return blob != null ? new String(blob.getBytes(1, (int) blob.length()), StandardCharsets.UTF_8) : ""; |
||||
} |
||||
|
||||
@Override |
||||
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { |
||||
Blob blob = cs.getBlob(columnIndex); |
||||
return blob != null ? new String(blob.getBytes(1, (int) blob.length()), StandardCharsets.UTF_8) : ""; |
||||
} |
||||
|
||||
@Override |
||||
public String getNullableResult(ResultSet rs, int i) throws SQLException { |
||||
Blob blob = rs.getBlob(i); |
||||
return blob != null ? new String(blob.getBytes(1, (int) blob.length()), StandardCharsets.UTF_8) : ""; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue