错误内容:
org.apache.ibatis.binding.BindingException: Mapper method 'getBillStateByDate' (interface com.aceway.settlement.mapper.SettlementMapper) attempted to return null from a method with a primitive return type (int).
网上解释使用ifnull函数,但是针对记录条数=0的情况,无任何作用。
抱着尝试的态度:java层使用Integer类型接收,mybatis层也改为返回Integer类型,可以捕获到Integer为空,进行判空后即可。
mybatis代码:
<select id="getBillStateByDate" parameterType="String" resultType="Integer">
select
state
from
result_bill
where
bill_date = #{bill_date}
limit 0,1
</select>
java代码:
Integer state = settlementMapper.getBillStateByDate(billDate);
if(state != null && state.intValue() > BillState.Temporary.value){
return -1;
}
希望对遇到此类问题的同伴有所帮助,有意见、建议的朋友敬请留言。
本文介绍了一种解决MyBatis中Mapper方法返回原始类型时出现BindingException异常的方法,并提供了一个具体的例子,通过调整Java层接收类型为Integer以及MyBatis映射文件中的返回类型,从而能够正确处理返回null的情况。
760

被折叠的 条评论
为什么被折叠?



