数据库中没有满足条件的id 就会报
HTTP Status 500 - Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Mapper method 'org.tsinghua.cis.dao.CisMedicineDetailsIdDao.findMedicineDetailsIdByClinicIdAndBarCode attempted to return null from a method with a primitive return type (int).
<select id="findMedicineDetailsIdByClinicIdAndBarCode" resultType="int">
<![CDATA[
SELECT
a.`id`
FROM
`cis_medicine_details_id` AS a
INNER JOIN
`cis_medicine_pricing` AS b
ON
a.id = b.medicine_details_id
WHERE
`medicine_bar_code` = ${medicineBarCode}
AND
`clinic_id` = ${clinicId}
]]>
</select>
解决方案
1.把resultType="int" 改为resultType="Integer"
在server层 判断 if(null==参数){
做相应的操作 是赋值0还是返回null 根据需要自行编写
}
2.使用IFNULL函数
<select id="findMedicineDetailsIdByClinicIdAndBarCode" resultType="int">
<![CDATA[
SELECT
IFNULL(a.`id`,0)
FROM
`cis_medicine_details_id` AS a
INNER JOIN
`cis_medicine_pricing` AS b
ON
a.id = b.medicine_details_id
WHERE
`medicine_bar_code` = ${medicineBarCode}
AND
`clinic_id` = ${clinicId}
]]>
</select>