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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
使用easyexcel導出的excel文件,使用poi讀取時異常處理方案
這篇文章主要介紹了使用easyexcel導出的excel文件,使用poi讀取時異常處理方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12