mybatic 结果为null,返回0

 

返回空容易产生异常,当值为null时,返回为0的写法

<select id="getBookWordCountBookPssAndChapterLockOrPass" resultType="LONG" parameterType="STRING">
        select  COALESCE(sum(word_count),0) as word_count
        from t_news_count 
        WHERE 
        chapter_id  in 
        ( SELECT chapter_id 
          from t_content_chapter  
          WHERE 
          book_id = #{book_id,jdbcType=VARCHAR} 
          AND  
          ( status = 3 OR status = 1) ) 
        AND 
        ( 3 = (SELECT current_state 
               FROM t_content_metadata 
               WHERE  book_id = #{book_id,jdbcType=VARCHAR} ) 
        ) 
    </select>

 

posted @ 2016-11-27 18:49  蔡昊  阅读(412)  评论(0编辑  收藏  举报