|
@@ -0,0 +1,49 @@
|
|
|
+package com.onemap.apply.config;
|
|
|
+
|
|
|
+import org.apache.ibatis.type.BaseTypeHandler;
|
|
|
+import org.apache.ibatis.type.JdbcType;
|
|
|
+
|
|
|
+import java.sql.*;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 字符串列表类型处理器
|
|
|
+ */
|
|
|
+public class StringListTypeHandler extends BaseTypeHandler<List<String>> {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
|
|
|
+ // 将 List<String> 转换为 PostgreSQL 数组类型
|
|
|
+ Connection conn = ps.getConnection();
|
|
|
+ Array array = conn.createArrayOf("text", parameter.toArray());
|
|
|
+ ps.setArray(i, array);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
|
|
+ Array array = rs.getArray(columnName);
|
|
|
+ if (array != null) {
|
|
|
+ return Arrays.asList((String[]) array.getArray());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
|
|
+ Array array = rs.getArray(columnIndex);
|
|
|
+ if (array != null) {
|
|
|
+ return Arrays.asList((String[]) array.getArray());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
|
|
+ Array array = cs.getArray(columnIndex);
|
|
|
+ if (array != null) {
|
|
|
+ return Arrays.asList((String[]) array.getArray());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|