2025/3/17 09:23:10---调整字符串与时间转换

This commit is contained in:
2025-03-17 01:24:18 +00:00 committed by root
parent 12ce84903f
commit f5ef46abd3

View File

@ -7,14 +7,14 @@ import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.JdbcType;
public class StringToTimestampTypeHandler extends BaseTypeHandler<String> {
public class StringToTimestampTypeHandler implements TypeHandler<String> {
private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
@Override
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
try {
ps.setLong(i, FORMAT.parse(parameter).getTime());
} catch (ParseException e) {
@ -23,19 +23,19 @@ public class StringToTimestampTypeHandler extends BaseTypeHandler<String> {
}
@Override
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
public String getResult(ResultSet rs, String columnName) throws SQLException {
long timestamp = rs.getLong(columnName);
return timestamp == 0 ? null : FORMAT.format(new java.util.Date(timestamp));
}
@Override
public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
public String getResult(ResultSet rs, int columnIndex) throws SQLException {
long timestamp = rs.getLong(columnIndex);
return timestamp == 0 ? null : FORMAT.format(new java.util.Date(timestamp));
}
@Override
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
public String getResult(CallableStatement cs, int columnIndex) throws SQLException {
long timestamp = cs.getLong(columnIndex);
return timestamp == 0 ? null : FORMAT.format(new java.util.Date(timestamp));
}