mybatis3.4.0不支持LocalDateTime的解決方法(No typehandler found for property time)
更新時間:2025年03月17日 10:57:43 作者:weixin_43833540
本文主要介紹了mybatis3.4.0不支持LocalDateTime的解決方法(No typehandler found for property time),具有一定的參考價值,感興趣的可以了解一下
問題描述
報錯:No typehandler found for property time
(注:time是LocalDateTime類型的字段)
LocalDateTimeTypeHandler
public class LocalDateTimeTypeHandler implements TypeHandler<LocalDateTime> {
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public void setParameter(PreparedStatement ps, int i, LocalDateTime parameter, JdbcType jdbcType) throws SQLException {
if (parameter != null) {
ps.setString(i, formatter.format(parameter));
} else {
ps.setTimestamp(i, null);
}
}
@Override
public LocalDateTime getResult(ResultSet rs, String columnName) throws SQLException {
String dateStr = rs.getString(columnName);
return dateStr == null ? null : LocalDateTime.parse(dateStr, formatter);
}
@Override
public LocalDateTime getResult(ResultSet rs, int columnIndex) throws SQLException {
String dateStr = rs.getString(columnIndex);
return dateStr == null ? null : LocalDateTime.parse(dateStr, formatter);
}
@Override
public LocalDateTime getResult(CallableStatement cs, int columnIndex) throws SQLException {
String dateStr = cs.getString(columnIndex);
return dateStr == null ? null : LocalDateTime.parse(dateStr, formatter);
}
}
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
</settings>
<typeHandlers>
<typeHandler handler="com.vanwardsmart.mybatis.LocalDateTimeTypeHandler" javaType="java.time.LocalDateTime"/>
</typeHandlers>
</configuration>到此這篇關(guān)于mybatis3.4.0不支持LocalDateTime的解決方法(No typehandler found for property time)的文章就介紹到這了,更多相關(guān)mybatis3.4.0不支持LocalDateTime內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot整合Security權(quán)限控制登錄首頁
這篇文章主要為大家介紹了SpringBoot整合Security權(quán)限控制登錄首頁示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
使用easyexcel導出的excel文件,使用poi讀取時異常處理方案
這篇文章主要介紹了使用easyexcel導出的excel文件,使用poi讀取時異常處理方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12

