mybatis配置文件中的統計注意: resultType="int"java
<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是這樣的: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 部分。apache
附 異常提示:mybatis
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).app