Mybatis

mybatis typeHandler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@MappedJdbcTypes(JdbcType.TIMESTAMP)
@MappedTypes(Long.class)
public class TimestampHandler extends BaseTypeHandler<Long> {

@Override
public void setNonNullParameter(PreparedStatement preparedStatement, int i, Long l, JdbcType jdbcType) throws SQLException {
preparedStatement.setTimestamp(i,new Timestamp(l));
}

@Override
public Long getNullableResult(ResultSet resultSet, String s) throws SQLException {
if(resultSet.getTimestamp(s) == null){
return null;
}else {
return resultSet.getTimestamp(s).getTime();
}
}

@Override
public Long getNullableResult(ResultSet resultSet, int i) throws SQLException {
return resultSet.getTimestamp(i).getTime();
}

@Override
public Long getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
return callableStatement.getTimestamp(i).getTime();
}
}

基于字段配置的jdbcType响应拦截进行替换

1
2
<id column="id" jdbcType="BIGINT" property="id" />