This commit is contained in:
2026-02-05 19:04:49 +08:00
parent e43757c4a1
commit 7cb90dfee8
28 changed files with 222 additions and 139 deletions

View File

@@ -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 TextArrayTypeHandler extends BaseTypeHandler<List<String>> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
// 将 List<String> 转换为 PostgreSQL 数组
Array array = ps.getConnection().createArrayOf("text", parameter.toArray());
ps.setArray(i, array);
}
@Override
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
// 从 ResultSet 中读取数组并转换为 List<String>
Array array = rs.getArray(columnName);
if (array == null) {
return null;
}
return Arrays.asList((String[]) array.getArray());
}
@Override
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
// 从 ResultSet 中按列索引读取数组并转换为 List<String>
Array array = rs.getArray(columnIndex);
if (array == null) {
return null;
}
return Arrays.asList((String[]) array.getArray());
}
@Override
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
// 从 CallableStatement 中读取数组并转换为 List<String>
Array array = cs.getArray(columnIndex);
if (array == null) {
return null;
}
return Arrays.asList((String[]) array.getArray());
}
}