您必须从TypeHandler的自定义实例开始.我们更喜欢实现更简单的TypeHandlerCallback,但在这种情况下,我们需要访问底层的Connection.
public class ArrayTypeHandler implements TypeHandler {
public void setParameter(PreparedStatement ps, int i, Object param, String jdbcType)
throws SQLException {
if (param == null) {
ps.setNull(i, Types.ARRAY);
} else {
Connection conn = ps.getConnection();
Array loc = conn.createArrayOf("myArrayType", (Object[]) param);
ps.setArray(i, loc);
}
}
public Object getResult(CallableStatement statement, int i)
throws SQLException {
return statement.getArray(i).getArray();
}
...
}
然后,在iBATIS配置中连接它:
{? = call My_Array_Function( ? )}
希望这可以帮助!