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>到此這篇關于mybatis3.4.0不支持LocalDateTime的解決方法(No typehandler found for property time)的文章就介紹到這了,更多相關mybatis3.4.0不支持LocalDateTime內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
spring boot 本地圖片不能加載(圖片路徑)的問題及解決方法
這篇文章主要介紹了spring boot 本地圖片不能加載(圖片路徑)的問題,解決的辦法其實很簡單,只要寫一個配置文件,也就是圖片位置的轉化器,原理是虛擬一個在服務器上的文件夾,與本地圖片的位置進行匹配。需要的朋友可以參考下2018-04-04
IDEA 2023創(chuàng)建JSP項目的完整步驟教程
這篇文章主要介紹了IDEA 2023創(chuàng)建JSP項目的完整步驟教程,創(chuàng)建項目需要經(jīng)過新建項目、設置項目名稱和路徑、選擇JDK版本、添加模塊和工件、配置Tomcat服務器等步驟,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2024-10-10

