Mybatis 报错 The error occurred while handling results,### Error querying database. Cause: java.lang.

小咪咪 2021-09-21 21:16 2349阅读 1赞
  1. select sum(patient_num) as patient_num from patient_report
  2. <where>
  3. project_id = #{projectId}
  4. <if test="siteId != null">
  5. and site_id = #{siteId}
  6. </if>
  7. </where>

数据库字段返回NULL时,报空指针异常
解决方法

  1. select COALESCE(sum(patient_num), 0) as patient_num from patient_report
  2. <where>
  3. project_id = #{projectId}
  4. <if test="siteId != null">
  5. and site_id = #{siteId}
  6. </if>
  7. </where>

加上COALESCE函数

发表评论

表情:
评论列表 (有 0 条评论,2349人围观)

还没有评论,来说两句吧...

相关阅读