日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jdk LocalDateTime mybatis 空指针解决办法

發布時間:2024/4/15 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jdk LocalDateTime mybatis 空指针解决办法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. mysql.mysql-connector-java:5.1.39

2. org.mybatis.mybatis:3.5.2

3.?org.mybatis.mybatis-spring:2.0.2

在項目中的mybats升級使用了jdk8的LocalDateTime等后,數據庫timesstamp字段有的記錄是null,導致查詢時出現下面錯誤

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'UPDATE_TIME' from result set. ?Cause: java.lang.NullPointerException
?? ?at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:78)
?? ?at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
?? ?at com.sun.proxy.$Proxy154.selectList(Unknown Source)
?? ?at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
?? ?at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
?? ?at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
?? ?at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)
?? ?at com.sun.proxy.$Proxy181.find(Unknown Source)
?? ?at cn.enn.ygego.sunny.sv.service.online.impl.LogisticsBrandServiceImpl.list(LogisticsBrandServiceImpl.java:67)
?? ?at cn.enn.ygego.sunny.sv.controller.online.LogisticsBrandController.list(LogisticsBrandController.java:49)
?? ?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?? ?at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
?? ?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
?? ?at java.lang.reflect.Method.invoke(Method.java:498)
不能把null轉換為LocalDateTime。通過跟蹤代碼,發現問題出在mysql的驅動上,JDBC42ResultSet的getObject代碼如下:

public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
? ? ? ? if (type == null) {
? ? ? ? ? ? throw SQLError.createSQLException("Type parameter can not be null", "S1009", this.getExceptionInterceptor());
? ? ? ? } else if (type.equals(LocalDate.class)) {
? ? ? ? ? ? return type.cast(this.getDate(columnIndex).toLocalDate());
? ? ? ? } else if (type.equals(LocalDateTime.class)) {
? ? ? ? ? ? return type.cast(this.getTimestamp(columnIndex).toLocalDateTime());
? ? ? ? } else if (type.equals(LocalTime.class)) {
? ? ? ? ? ? return type.cast(this.getTime(columnIndex).toLocalTime());
? ? ? ? } else {
? ? ? ? ? ? if (type.equals(OffsetDateTime.class)) {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? return type.cast(OffsetDateTime.parse(this.getString(columnIndex)));
? ? ? ? ? ? ? ? } catch (DateTimeParseException var5) {
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } else if (type.equals(OffsetTime.class)) {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? return type.cast(OffsetTime.parse(this.getString(columnIndex)));
? ? ? ? ? ? ? ? } catch (DateTimeParseException var4) {
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
?
? ? ? ? ? ? return super.getObject(columnIndex, type);
? ? ? ? }
? ? }
return type.cast(this.getTimestamp(columnIndex).toLocalDateTime());代碼中this.getTimestamp(columnIndex)返回null,再次執行toLocalDateTime(),當然報錯。
解決方式升級mysql驅動,我升級到5.1.47,其他版本沒有測試,在5.1.47中代碼如下:

public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
? ? ? ? if (type == null) {
? ? ? ? ? ? throw SQLError.createSQLException("Type parameter can not be null", "S1009", this.getExceptionInterceptor());
? ? ? ? } else if (type.equals(LocalDate.class)) {
? ? ? ? ? ? Date date = this.getDate(columnIndex);
? ? ? ? ? ? return date == null ? null : type.cast(date.toLocalDate());
? ? ? ? } else if (type.equals(LocalDateTime.class)) {
? ? ? ? ? ? Timestamp timestamp = this.getTimestamp(columnIndex);
? ? ? ? ? ? return timestamp == null ? null : type.cast(timestamp.toLocalDateTime());
? ? ? ? } else if (type.equals(LocalTime.class)) {
? ? ? ? ? ? Time time = this.getTime(columnIndex);
? ? ? ? ? ? return time == null ? null : type.cast(time.toLocalTime());
? ? ? ? } else {
? ? ? ? ? ? String string;
? ? ? ? ? ? if (type.equals(OffsetDateTime.class)) {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? string = this.getString(columnIndex);
? ? ? ? ? ? ? ? ? ? return string == null ? null : type.cast(OffsetDateTime.parse(string));
? ? ? ? ? ? ? ? } catch (DateTimeParseException var5) {
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } else if (type.equals(OffsetTime.class)) {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? string = this.getString(columnIndex);
? ? ? ? ? ? ? ? ? ? return string == null ? null : type.cast(OffsetTime.parse(string));
? ? ? ? ? ? ? ? } catch (DateTimeParseException var4) {
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
?
? ? ? ? ? ? return super.getObject(columnIndex, type);
? ? ? ? }
? ? }
明顯看到增加null判斷。

總結

以上是生活随笔為你收集整理的jdk LocalDateTime mybatis 空指针解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品日本 | 91精品久久久久久久99蜜桃 | 最新中文字幕在线 | 精品无码人妻一区二区三区 | 蜜臀一区二区三区精品免费视频 | 国产精品永久免费观看 | 91精品国产综合久久国产大片 | 人人91 | 91成人福利视频 | 国产sm调教一区二区 | 久久久久99精品成人片三人毛片 | www国产com| 丝袜美腿一区二区三区 | 欧美一区精品 | 献给魔王伊伏洛基亚吧动漫在线观看 | 国产精品主播在线 | 国产电影一区二区三区爱妃记 | 日韩黄色精品 | 久久久久成人精品无码中文字幕 | 成人h动漫精品一区 | 男女午夜视频在线观看 | 二区三区在线视频 | 91一区二区在线 | 原来神马电影免费高清完整版动漫 | 毛片基地视频 | 国产区免费 | 丰满人妻在公车被猛烈进入电影 | 欧美精品91| 色屁屁一区二区 | 无码人妻精品一区二区三区99v | 国产色无码精品视频国产 | 欧美激情专区 | 日韩在线欧美 | 久草手机在线观看 | 亚洲综合一区中 | 国产网站在线免费观看 | 欧亚乱熟女一区二区在线 | 成人午夜免费毛片 | 国av在线 | 国产人妻精品久久久久野外 | 日本高清免费不卡视频 | 黄色片a级| 视频在线观看视频 | 日韩精品一区二区在线 | 黄色aa网站 | 亚洲精品88 | 台湾佬美性中文娱乐网 | 色天天| 黄色片日韩 | 久久黄色一级视频 | 亚洲在线一区二区三区 | 女教师三上悠亚ssni-152 | 国产欧美啪啪 | 蜜臀av夜夜澡人人爽人人 | 久久久久久久久蜜桃 | 中文视频一区二区 | 国产精品福利小视频 | 国产一区视频在线播放 | 成人网址在线观看 | 午夜一区二区三区四区 | 亚洲人人夜夜澡人人爽 | 国产一区二区三区四区五区美女 | 日韩欧美91 | 国产乱码一区二区三区播放 | 手机在线一区 | 国产白丝一区二区三区 | 国产精品国产三级国产普通话蜜臀 | 日韩欧美一区二区三区免费观看 | 午夜播放 | 亚洲精品推荐 | jizz色| 日韩在线一 | 国内av网 | 三级在线看中文字幕完整版 | 自拍偷拍欧美激情 | avtt在线观看 | 男女猛烈无遮挡免费视频 | 精品国产网 | 亚洲精品乱码久久久久 | 天天摸天天干天天操 | 亚洲欧美在线播放 | 国产精品手机在线 | 亚洲美女视频 | 九九热视频精品在线观看 | 国产毛片视频 | 久久人人精 | 巨大乳の揉んで乳榨り奶水 | 欧美日韩一级黄色片 | 色在线免费| 蜜桃视频污| 亚洲一区人妻 | 色一情一乱一伦 | 亚州国产精品视频 | 欧美中文字幕第一页 | 日韩1级片 | 蜜桃精品在线观看 | 亚洲国产欧美视频 | 日本污视频在线观看 | www.youji.com|