1. 程式人生 > >attempted to return null from a method with a primitive return type (Double).

attempted to return null from a method with a primitive return type (Double).

span att 但是 sele 代碼 mysql from ive star

  1. <select id="getMaxHitEventId" parameterType="string" resultType="int">
  2. select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV}
  3. </select>

mybatis+mysql查詢出來會報如下錯誤:
attempted to return null from a method with a primitive return type (int).
我的返回值類型為int,但是查詢出來的結果有空值,所以會出現如上的異常,以下為解決辦法:

1.當查詢出來為空時,給賦值一個默認值:

  1. select IFNULL(max(app_hitEventID),0) from hits_tab_app where app_hitV=#{app_hitV}

2.將返回值類型改為Integer,然後由業務代碼去進行判斷:

  1. <select id="getMaxHitEventId" parameterType="string" resultType="Integer">
  2. select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV}
  3. </select>

attempted to return null from a method with a primitive return type (Double).