支持叙利亚不含糊 中国提供情报武器,卡布西游飞来的诅咒,中国饲料排行榜
在Mybatis中读写数据库时joda-time时间类型转换器 标签: <无>代码片段(3) [全屏查看所有代码]
1. [文件] DateTimeTypeHandler.java ~ 2KB 下载(0) 跳至 [1] [全屏预览]
package com.diary.util; import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.TypeHandler; import org.joda.time.LocalDateTime; /** * joda-time时间类型转换器 * 实现TypeHandler接口 * 需要强调的是:为了让类型控制器起作用,必须在mapper.xml中对参数和结果的类型进行显示表明。 * @author fcy */ public class DateTimeTypeHandler implements TypeHandler<LocalDateTime> { @Override public void setParameter(PreparedStatement preparedStatement, int i, LocalDateTime dateTime, JdbcType jdbcType) throws SQLException { if (dateTime != null) { preparedStatement.setTimestamp(i, new Timestamp(dateTime.toDateTime().getMillis())); } else { preparedStatement.setTimestamp(i, null); } } @Override public LocalDateTime getResult(ResultSet resultSet, String s) throws SQLException { return toDateTime(resultSet.getTimestamp(s)); } @Override public LocalDateTime getResult(ResultSet resultSet, int i) throws SQLException { return toDateTime(resultSet.getTimestamp(i)); } @Override public LocalDateTime getResult(CallableStatement callableStatement, int i) throws SQLException { return toDateTime(callableStatement.getTimestamp(i)); } private static LocalDateTime toDateTime(Timestamp timestamp) { if (timestamp != null) { LocalDateTime dateTime = new LocalDateTime(timestamp); return dateTime; } else { return null; } } }
2. [图片] mapper.png
3. [图片] Mybatis-config.png
spring4+springMVC+mybatis+activiti+maven
<无详细内容>标签:-->-->-->1.[文件]xxl_maven_web.
Mybatis读写数据库时处理jodatime
在Mybatis中读写数据库时joda-time时间类型转换器标签:<无>-->-->-->1.[文件]DateTimeTypeHandler.java~2KB(0)packagecom.diary.