- <select id="getMaxHitEventId" parameterType="string" resultType="int">
- select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV}
- </select>
mybatis+mysql查詢出來會報如下錯誤:
attempted to return null from a method with a primitive return type (int).
我的返回值類型為int,但是查詢出來的結果有空值,所以會出現如上的異常,以下為解決辦法:
1.當查詢出來為空時,給賦值一個默認值:
- select IFNULL(max(app_hitEventID),0) from hits_tab_app where app_hitV=#{app_hitV}
2.將返回值類型改為Integer,然后由業務代碼去進行判斷:
- <select id="getMaxHitEventId" parameterType="string" resultType="Integer">
- select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV}
- </select>