12345678910111213141516171819202122232425262728293031323334353637383940 |
- package cn.iselab.mooctest.user.config;
- import org.apache.ibatis.type.JdbcType;
- import org.apache.ibatis.type.TypeHandler;
- import java.sql.*;
- /**
- * @author sean
- * @date 2018-03-15.
- */
- public class NullValueHandler implements TypeHandler<String> {
- @Override
- public String getResult(ResultSet rs, String columnName) throws SQLException {
- return rs.getString(columnName);
- }
- @Override
- public String getResult(ResultSet rs, int columnIndex) throws SQLException {
- return rs.getString(columnIndex);
- }
- @Override
- public void setParameter(PreparedStatement preparedStatement, int i, String s, JdbcType jdbcType) throws SQLException {
- if (s == null &&
- jdbcType == JdbcType.VARCHAR
- // || jdbcType == JdbcType.TIMESTAMP || jdbcType == JdbcType.BIGINT || jdbcType == JdbcType.TINYINT || jdbcType == JdbcType.INTEGER)
- ) {
- preparedStatement.setString(i, "");
- } else {
- preparedStatement.setString(i, s);
- }
- }
- @Override
- public String getResult(CallableStatement callableStatement, int i) throws SQLException {
- return callableStatement.getString(i);
- }
- }
|