Mybatis报错attempted to return null from a method with a primitive return type (int)(已解决)
一、出现这个bug的原因 出现这个bug的原因是因为MyBatis的Mapper.xml文件的查询语句返回的结果是Integer类型,而在对应的接口里面的方法里返回参数的类型是int。如果这个查询语句查询出来的结果是null,则会报这个错误,最简单的解决办法就是返回值的类型统一用Integer类型,或者在sql语句里面用ifnull()的函数,当查询结果是null时,给个默认值0。 二、错误示范 …