错误产生的场景

  • dao层接口如下
int getResourceDataNumsByTitle(String title);
  • mapper.xml 中sql语句如下
<select id="getResourceDataNumsByTitle" parameterType="java.lang.String" resultType="java.lang.Integer">SELECT * FROM t_resourceData where title = #{title}
</select>
  • Service层
for(ResourceData r : resourceDatas){if(!(getResourceDataNumsByTitle(r.getTitle()) > 0)){resourceMapper.insertOneResourceData(r);LOG.info(r.getTitle()+"已插入");}
}
  • 报错如下
org.apache.ibatis.binding.BindingException: Mapper method 'com.haoeasy.news.mapper.ResourceMapper.getResourceDataNumsByTitle 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)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
0
2019-04-12 20:30:00.171  INFO 10648 --- [       Thread-2] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2019-04-12 20:30:00.177  INFO 10648 --- [       Thread-2] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} closedProcess finished with exit code 0

错误原因

  • 分析

本次报错的原因在于sql语句未查询到数据,返回为null。而我们定义的dao层方法是返回为int,就会出现如下这样的提示:
return null from a method with a primitive return type (int).(试图从具有原始返回类型(int)的方法返回null)
Ingeter是int的包装类,int的初值为0,Ingeter的初值为null

  • 解决方式

将dao层的返回类型改为Integer即可。

attempted to return null from a method with a primitive return type (int).相关推荐

  1. 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.getAdmin ...

  2. Mybatis:Mapper method attempted to return null from a method with a primitive return type (int)

    Mybatis中 Mapper method attempted to return null from a method with a primitive return type (int)错误 本 ...

  3. sql报错解决方案:attempted to return null from a method with a primitive return type (int)

    问题现象 idea执行查询数量语句控制台报错:attempted to return null from a method with a primitive return type (int). 解决 ...

  4. 关于mybatis的报错 attempted to return null from a method with a primitive return type (int)

    https://blog.csdn.net/kisscatforever/article/details/77801060 一.前言       在往常敲代码的时候没有留意过int和Integer的区 ...

  5. Mybatis-增删改查踩坑- attempted to return null from a method with a primitive return type (int).

    错误 在编写插入数据时一直报如下错误: attempted to return null from a method with a primitive return type (int). 原来的代码 ...

  6. Mybatis异常错误:Mapper method attempted to return null from a method with a primitive return type (int)

    在mybatis搭建时出现错误:Mapper method attempted to return null from a method with a primitive return type (i ...

  7. error:attempted to return null from a method with a primitive return type (int)

    1,起因 今天老大让改bug,说有个模块数据提交不了,让我看看...检查服务器发现这个报错..attempted to return null from a method with a primiti ...

  8. mapper method attempted to return null from a method with a primitive return type (int)

    一.场景和背景 工具:mybatis + pgsql dao代码: int selectMaxAgeBySex(String sex); 查询性别是女生的最大年龄 sql: <select id ...

  9. insertRole attempted to return null from a method with a primitive return type

    练习myBatis,向数据库插入一条数据,期望返回1,结果报错. 多次查找,结果是Mapper对应的xml文件中sql语句的节点写成select了,应该是insert

最新文章

  1. 23 年码农经历,33 次创业失败,38 岁身价百亿,快手创始人宿华的逆袭史!
  2. iOS消息推送机制原理与实现
  3. nginx常用代理配置
  4. Python入门100题 | 第038题
  5. windowsXP用VNC客户端连接centos6桌面后再用tsclient连接windows2003/2008桌面
  6. python判断奇偶数字符串的拼接_Python字符串拼接方法总结
  7. LeetCode 22. 括号生成(回溯/DP)
  8. WordPress:如何判断登录用户的角色
  9. 使用工具Csvde导出域中所有用户信息
  10. 在Unity中实现屏幕空间反射Screen Space Reflection(2)
  11. spark checkpoint
  12. php读取/写入mssql乱码!(续...重要)
  13. BZOJ 3509 分块FFT
  14. 我心目中的支付宝架构
  15. debian9中文办公环境字体设置
  16. 服务机器人语音对话的实现
  17. oppor17刷鸿蒙系统,oppo a5刷机包下载
  18. android信鸽推送demo_腾讯信鸽推送(java版)
  19. a-btest 数据挖掘_挖掘新的垂直鼠标-帮助我的腕管
  20. 天下武功唯快不破,实时分析让企业决策又快又准

热门文章

  1. Ecowalker充气足球门,为青少年足球训练保驾护航!
  2. 远程协作从“特殊”到“常态”,你可能需要的会议平板测评
  3. 【C/C++】输入一个整数的二目运算式的字符串,如100+20,332-19,200*2333,44/33二目运算取”加减乘除“中的一种输出运算式的整数结果值
  4. Android sockot连接打印机EPSON ESC/POS指令打印
  5. Python自动化 | 通过键盘控制鼠标来玩赛尔号
  6. 微信小程序反编译wxss文件缺失_反编译任何微信小程序和如何还原wxss
  7. 手机刷机的几种常用方法
  8. 计算机 黑屏 显示桌面,电脑开机后显示桌面黑屏了怎么处理啊?
  9. 论文解读:《利用深度学习方法识别RNA伪尿苷位点》
  10. 自己搜的算法题2.0