|
|
@ -1,43 +0,0 @@ |
|
|
|
package com.example.demo.Util; |
|
|
|
|
|
|
|
import org.apache.ibatis.type.BaseTypeHandler; |
|
|
|
import org.apache.ibatis.type.JdbcType; |
|
|
|
import org.apache.ibatis.type.TypeHandler; |
|
|
|
|
|
|
|
import java.sql.CallableStatement; |
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
public class StringToListTypeHandler extends BaseTypeHandler<List<String>> { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException { |
|
|
|
// 将 List<String> 转换为字符串 |
|
|
|
ps.setString(i, String.join(",", parameter)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException { |
|
|
|
return parseStringToList(rs.getString(columnName)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException { |
|
|
|
return parseStringToList(rs.getString(columnIndex)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { |
|
|
|
return parseStringToList(cs.getString(columnIndex)); |
|
|
|
} |
|
|
|
|
|
|
|
private List<String> parseStringToList(String str) { |
|
|
|
if (str == null || str.isEmpty()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return Arrays.asList(str.split(",")); |
|
|
|
} |
|
|
|
} |