mybatis配置文件中的统计注意: resultType="int"
<select id="listOrderCount" resultType="int" parameterType="java.util.HashMap">
SELECT
count(1)
FROM hdx_users,hdx_order_headers
WHERE hdx_users.`id` = hdx_order_headers.`user_id`
<if test="parentId != null and parentId != 0">
AND hdx_users.parent_id = #{parentId}
</if>
AND hdx_order_headers.order_transaction_type = '1'
AND hdx_order_headers.`pay_flag` = 2
<if test="mobile != null and mobile != ''">
AND hdx_users.`mobile` = #{mobile}
</if>
<if test="requestStartDate != null and requestStartDate != ''">
AND hdx_order_headers.request_date > DATE_FORMAT(#{requestStartDate}, '%Y-%m-%d/%H:%i:%s')
</if>
<if test="requestEndDate != null and requestEndDate != ''">
AND hdx_order_headers.request_date < DATE_FORMAT(#{requestEndDate}, '%Y-%m-%d/%H:%i:%s')
</if>
ORDER BY hdx_order_headers.`gmt_modified` DESC
limit #{begin},#{pageSize}
</select>
查询时,统计SQL是这样的:
SELECT
COUNT(1)
FROM hdx_users,
hdx_order_headers
WHERE hdx_users.`id` = hdx_order_headers.`user_id`
AND hdx_users.parent_id = 308
AND hdx_order_headers.order_transaction_type = '1'
AND hdx_order_headers.`pay_flag` = 2
ORDER BY hdx_order_headers.`gmt_modified` DESC
LIMIT 40,20
那么这里就出现问题了。limit 40,20 可能使数据查询无值。导致sql返回的值 是无值。注意是无值,连Null都不是,这样根本无法将它转成int类型。
所以以且请大家注意,统计语句如果你是从分页查询语句 中复制过来的,一定要记得删除 后面的 limit 和order by 部分。
附 异常提示:
org.apache.ibatis.binding.BindingException: Mapper method 'listOrderByProductleaderCount' (interface com..business.productleader.dao.HdxUserDayIncomeDao) attempted to return null from a method with a primitive return type (int).
来源:oschina
链接:https://my.oschina.net/u/2553994/blog/661664