feat:
1. add user_market_info
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
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;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@MappedJdbcTypes(JdbcType.ARRAY)
|
||||||
|
@MappedTypes(List.class)
|
||||||
|
public class PgStringArrayToListTypeHandler extends BaseTypeHandler<List<String>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
|
||||||
|
if (parameter == null || parameter.isEmpty()) {
|
||||||
|
ps.setNull(i, Types.ARRAY);
|
||||||
|
} else {
|
||||||
|
Array array = ps.getConnection().createArrayOf("TEXT", parameter.toArray());
|
||||||
|
ps.setArray(i, array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||||
|
return parseArray(rs.getArray(columnName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
|
return parseArray(rs.getArray(columnIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||||
|
return parseArray(cs.getArray(columnIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> parseArray(Array array) throws SQLException {
|
||||||
|
if (array == null) return null;
|
||||||
|
Object[] objects = (Object[]) array.getArray();
|
||||||
|
return Arrays.stream(objects)
|
||||||
|
.map(Object::toString)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user