Mybatis 报错 The error occurred while handling results,### Error querying database. Cause: java.lang.
select sum(patient_num) as patient_num from patient_report<where>project_id = #{projectId}<if test="siteId != null">and site_id = #{siteId}</if></where>数据库字段返回NULL时,报空指针异常解决方法s
·
select sum(patient_num) as patient_num from patient_report
<where>
project_id = #{projectId}
<if test="siteId != null">
and site_id = #{siteId}
</if>
</where>
数据库字段返回NULL时,报空指针异常
解决方法
select COALESCE(sum(patient_num), 0) as patient_num from patient_report
<where>
project_id = #{projectId}
<if test="siteId != null">
and site_id = #{siteId}
</if>
</where>
加上COALESCE函数
更多推荐
所有评论(0)