Mybatis中的attempted to return null from a method with a primitive return type (int).异常
生活随笔
收集整理的這篇文章主要介紹了
Mybatis中的attempted to return null from a method with a primitive return type (int).异常
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
錯誤截圖:
org.apache.ibatis.binding.BindingException: Mapper method 'com.shop_demo.dao.AdminDAO.getAdminByNameAndPassword attempted to return null from a method with a primitive return type (int).at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:102)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)at com.sun.proxy.$Proxy8.getAdminByNameAndPassword(Unknown Source)at com.test.admin.admintest.get(admintest.java:55)at com.test.admin.admintest.main(admintest.java:74)翻譯過來是:
試圖從具有基元返回類型(int)的方法返回空值。解決辦法:
將返回值boolean封裝數據類型為Boolean、int封裝數據類型為Integer。
當boolean、int、long等數據類型作為返回值時,用mybatis查詢的結果null時,會出現錯誤,查了查才發現這些基本數據類型是不能定義為null的。
也就是說當數據庫查詢結果為null時,不能直接使用boolean、int、long等基本數據類型作為返回值。
總結
以上是生活随笔為你收集整理的Mybatis中的attempted to return null from a method with a primitive return type (int).异常的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot+mybatis测试
- 下一篇: nginx实现前后端分离