ibatis时间转换源码分析
package com.ibatis.sqlmap.engine.mapping.parameter
setParameters()中setParameter()加载了TypeHandler
对于java.util.date:
public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType) throws SQLException { ps.setTimestamp(i, new java.sql.Timestamp(((Date) parameter).getTime())); } public Object getResult(ResultSet rs, String columnName) throws SQLException { java.sql.Timestamp sqlTimestamp = rs.getTimestamp(columnName); if (rs.wasNull()) { return null; } else { return new java.util.Date(sqlTimestamp.getTime()); } }
对于java.sql.Timestamp
public class SqlTimestampTypeHandler extends BaseTypeHandler implements TypeHandler { private static final String DATE_FORMAT = "yyyy/MM/dd hh:mm:ss"; public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType) throws SQLException { ps.setTimestamp(i, (java.sql.Timestamp) parameter); } public Object getResult(ResultSet rs, String columnName) throws SQLException { Object sqlTimestamp = rs.getTimestamp(columnName); if (rs.wasNull()) { return null; } else { return sqlTimestamp; } }
...
}
作者:五岳
出处:http://www.cnblogs.com/wuyuegb2312
对于标题未标注为“转载”的文章均为原创,其版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。