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
  • 相关阅读:
    朴素贝叶斯分类模型
    进程同步机制
    Django知识点汇总
    Django框架_URLconf、Views、template、ORM
    WebSocket介绍
    Django小练习
    数据库(11)-- Hash索引和BTree索引 的区别
    MySQL数据库--练习
    Web 框架 Flask
    Django之Model操作
  • 原文地址:https://www.cnblogs.com/wongzzh/p/15103881.html
Copyright © 2011-2022 走看看