修bug
This commit is contained in:
@@ -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++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user