• Mybatis报错 attempted to return null from a method with a primitive return type (int).


    1、报错信息

    org.apache.ibatis.binding.BindingException: Mapper method 'xxxMapper.XXX attempted 
    to return null from a method with a primitive return type (int).
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:93)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
        at com.sun.proxy.$Proxy71.getResourceDataNumsByTitle(Unknown Source)
        at com.haoeasy.news.serviceimpl.ResourceServiceImpl.getResourceDataNumsByTitle(ResourceServiceImpl.java:39)
        at com.haoeasy.news.serviceimpl.ResourceServiceImpl.insertOneResourceData(ResourceServiceImpl.java:23)
        at com.haoeasy.news.news.NewsApplicationTests.getUrlContent(NewsApplicationTests.java:105)
        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)
    报错的原因在于sql语句未查询到数据,返回为null。而我们定义的dao层方法是返回为int,就会出现如下这样的提示:
    return null from a method with a primitive return type (int).(试图从具有原始返回类型(int)的方法返回null)
    Ingeter是int的包装类,int的初值为0,Ingeter的初值为null

    2、解决方式:

    将dao层的返回类型改为Integer
  • 相关阅读:
    非冒泡事件的冒泡支持
    js--题目二
    js-- 一些题目
    jQuery 请指出'$'和'$.fn'的区别?或者说出'$.fn'的用途。
    jQuery 请指出'.bind()','.live()'和'.delegate()'的区别
    什么时候不能完全按照设计稿来
    edm注意细节
    响应式设计
    css -- 题目汇总
    什么是Handler(四)
  • 原文地址:https://www.cnblogs.com/wongzzh/p/15103881.html
Copyright © 2020-2023  润新知