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

java.lang.NullPointerExceptionmapper.xxxx ActivityMapper.selectCountOfActivityByCondition(java.util.Map)" is nul

jakarta.servlet.ServletException: Request processing failed: java.lang.NullPointerException: Cannot invoke “java.lang.Integer.intValue()” because the return value of “com.bjpowernode.crm.workbench.mapper.ActivityMapper.selectCountOfActivityByCondition(java.util.Map)” is nul
今天做项目时候,mapper层一直显示再爆空指针异常,检查发现是在查询总记录条数时,不小心把分页的条件加在了where那里。导致查第一页没有问题,分页查第二页的时候一直报错。

问题分析

第一页不出问题是,查询总记录条数是只有一行,一个数字,满足分页的第一页数据。相当于分页数据只有第一页的第一条存在。但是当查询第二页时,总共只有一行数据且在第一页的第一行,所以第二页是肯定没有数据的,但是sql语句where又要进行分页返回第二页的数据,所以导致查询到的条数为空所以爆空指针异常
【Mybatis报错】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)._第2张图片

你可能感兴趣的:(mybatis框架篇,mysql篇,异常报错总结,mybatis,java,sql,数据库)