zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    python学习笔记1--datetime的使用
    python学习笔记2--子类父类继承时的参数传递
    python学习笔记1--错误,异常,调试
    JS同异步编程
    AMD /CMD
    i++ && ++i
    将url问号后面的参数变成对象
    字符串的常用方法
    函数 && 函数运行机制
    Math数学函数及常用方法
  • 原文地址:https://www.cnblogs.com/wongzzh/p/15103881.html
Copyright © 2011-2022 走看看