- 当mybtis统计条数返回int类型,会报如下错:
org.apache.ibatis.binding.BindingException: Mapper method 'getSort' (xx.yy.cc.DxxDAO) attempted to return null from a method with a primitive return type (int).
-
报这种错的原因是因为返回类型是int类型,结果返回null
解决方案:
- 将返回参数类型改为integer
<select id="countRecords" resultType="Integer" parameterType="com.FundRebateMdrApplyEntity">
select
count(*) from apply
</select>
- 如果不想动xml里边的东西,我们可以在查询这条数据的时候,对他进行为空的判断
<select id="countRecords" resultType="int" parameterType="com.FundRebateMdrApplyEntity">
select
count(*) from apply
</select>
PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize(), false);
List<Entity> ApplyMapper.findRecords(
PageInfo<FunMdrApplyDto> pageResult = new PageInfo<>();
// 若查询分页数据为空
if (ObjectUtils.isEmpty(entityList)) {
pageResult.setList(null);
pageResult.setTotal(0);
return pageResult;
}
博主个人觉得第二种偏好一点,以便于后边的代码优化,就算传的null,也不会报错!!