publicEnumValueHandler(Class<E> type) { if (type == null) thrownewIllegalArgumentException("type不得为null"); this.type = type; E[] enums = this.type.getEnumConstants(); this.codeToEnum = newHashMap<>(enums.length); for (E e : enums) { this.codeToEnum.put(e.getCode(), e); } }
@Override publicvoidsetNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType)throws SQLException { ps.setInt(i, parameter.getCode()); }
@Override public E getNullableResult(ResultSet rs, String columnName)throws SQLException { intvalue= rs.getInt(columnName); if (rs.wasNull()) { returnnull; } return codeToEnum.get(value); }
@Override public E getNullableResult(ResultSet rs, int columnIndex)throws SQLException { inti= rs.getInt(columnIndex); if (rs.wasNull()) { returnnull; } else { return codeToEnum.get(i); } }
@Override public E getNullableResult(CallableStatement cs, int columnIndex)throws SQLException { inti= cs.getInt(columnIndex); if (cs.wasNull()) { returnnull; } else { return codeToEnum.get(i); } }