TypeHandler
是用于 类型处理,ORM 框架的一大核心,处理 jdbc 和 编程语言之间的类型转换,TypeHandler
处理两部分数据;
mapper
操作数据库,编程语言类型,转数据库类型。/*** 类型处理** @author Clinton Begin*/public interface TypeHandler<T> {/*** 设置 PreparedStatement 的指定参数** Java Type => JDBC Type** @param ps PreparedStatement 对象* @param i 参数占位符的位置* @param parameter 参数* @param jdbcType JDBC 类型* @throws SQLException 当发生 SQL 异常时*/void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException;/*** 获得 ResultSet 的指定字段的值** JDBC Type => Java Type** @param rs ResultSet 对象* @param columnName 字段名* @return 值* @throws SQLException 当发生 SQL 异常时*/T getResult(ResultSet rs, String columnName) throws SQLException;/*** 获得 ResultSet 的指定字段的值** JDBC Type => Java Type** @param rs ResultSet 对象* @param columnIndex 字段位置* @return 值* @throws SQLException 当发生 SQL 异常时*/T getResult(ResultSet rs, int columnIndex) throws SQLException;/*** 获得 CallableStatement 的指定字段的值** JDBC Type => Java Type** @param cs CallableStatement 对象,支持调用存储过程* @param columnIndex 字段位置* @return 值* @throws SQLException*/T getResult(CallableStatement cs, int columnIndex) throws SQLException;}
说明:
CallableStatement
用于存储过程的处理方式。完结~