This commit is contained in:
KilLze
2025-12-29 15:16:59 +08:00
parent 7601fbb3c0
commit 59838e1f5b

View File

@@ -6,10 +6,7 @@ import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes; import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler; import org.apache.ibatis.type.TypeHandler;
import java.sql.CallableStatement; import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -22,6 +19,11 @@ import java.util.List;
public class ListToVarcharTypeHandler implements TypeHandler<List<String>> { public class ListToVarcharTypeHandler implements TypeHandler<List<String>> {
@Override @Override
public void setParameter(PreparedStatement preparedStatement, int i, List<String> strings, JdbcType jdbcType) throws SQLException { public void setParameter(PreparedStatement preparedStatement, int i, List<String> strings, JdbcType jdbcType) throws SQLException {
// 允许 null
if (strings == null || strings.isEmpty()) {
preparedStatement.setNull(i, Types.VARCHAR);
return;
}
// 遍历List类型的入参拼装为String类型使用Statement对象插入数据库 // 遍历List类型的入参拼装为String类型使用Statement对象插入数据库
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int j = 0; j < strings.size(); j++) { for (int j = 0; j < strings.size(); j++) {