1
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package org.springblade.common.handler;
|
||||
|
||||
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 java.sql.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@MappedJdbcTypes(JdbcType.ARRAY)
|
||||
@MappedTypes(List.class)
|
||||
public class PgBigIntArrayToListTypeHandler extends BaseTypeHandler<List<Long>> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<Long> parameter, JdbcType jdbcType) throws SQLException {
|
||||
// 将 List<Long> 转换为 PostgreSQL 的 bigint[]
|
||||
Array array = ps.getConnection().createArrayOf("bigint", parameter.toArray());
|
||||
ps.setArray(i, array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
// 从 ResultSet 中读取数组并转换为 List<Long>
|
||||
Array array = rs.getArray(columnName);
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.asList((Long[]) array.getArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
// 从 ResultSet 中按列索引读取数组并转换为 List<Long>
|
||||
Array array = rs.getArray(columnIndex);
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.asList((Long[]) array.getArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
// 从 CallableStatement 中读取数组并转换为 List<Long>
|
||||
Array array = cs.getArray(columnIndex);
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.asList((Long[]) array.getArray());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user