idea报错:Mapper method ……attempted to return null from a method with a primitive return type (int).

问题描述

学习黑马课程时,在idea中运行tomcat时查不到数据,错误信息如下:

Caused by: org.apache.ibatis.binding.BindingException: Mapper method 'com.itheima.mapper.BrandMapper.selectTotalCount 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 P l a i n M e t h o d I n v o k e r . i n v o k e ( M a p p e r P r o x y . j a v a : 152 ) a t o r g . a p a c h e . i b a t i s . b i n d i n g . M a p p e r P r o x y . i n v o k e ( M a p p e r P r o x y . j a v a : 85 ) a t c o m . s u n . p r o x y . PlainMethodInvoker.invoke(MapperProxy.java:152) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) at com.sun.proxy. PlainMethodInvoker.invoke(MapperProxy.java:152)atorg.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)atcom.sun.proxy.Proxy32.selectTotalCount(Unknown Source)
at com.itheima.service.impl.BrandServiceImpl.selectByPage(BrandServiceImpl.java:70)
at com.itheima.web.servlet.BrandServlet.selectByPage(BrandServlet.java:71)
… 25 more

原因分析

出错原因是方法selectTotalCount的返回值类型为int,执行方法时却试图返回null,而int的默认值为0,与null不兼容,需要把int类型换成其包装类型Integer

解决方案

  1. 修改pojo包下的PageBean类,将totalCount的类型改为Integergettersetter方法的类型也要改:

image.png

  1. 修改dao层BrandMapper类,将方法selectTotalCount的返回值类型改为Integer

image.png

  1. 修改service层BrandServiceImpl类,将方法selectByPagetotalCount的类型改为Integer

image.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

在逃八阿哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值