1. 自定义TypeHandler
下面是一个自定义的用于处理Set<Long>
类型的类型处理器
用于处理:Java实体类属性Set<Long>
[1, 2, 3, 4]
<–> 数据库表字段varchar(255)
1,2,3,4
public class SetTypeHandler extends BaseTypeHandler<Set<Long>> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Set<Long> parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i, convertSetToString(parameter));
}
@Override
public Set<Long> getNullableResult(ResultSet rs, String columnName) throws SQLException {
return convertStringToSet(rs.getString(columnName));
}
@Override
public Set<Long> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
return convertStringToSet(rs.getString(columnIndex))