mapper.xml里返回类型是int,但是查询的结果是null

方法一:IFNULL(栏位名, 0)

<select id="getTotalCount" resultType="java.lang.Integer">
	select IFNULL((max(quantity) - min(quantity)), 0) as result from machine where machine = 'XX'
</select>

方法二:
在ServiceImpl中写处理逻辑

	Integer totalCount = motiveMapper.getTotalCount(startDate, nowDate);
    if(totalCount==null){
        totalCount = 0;
    }
    return totalCount;	
<select id="getTotalCount" resultType="java.lang.Integer">
</select>

你可能感兴趣的:(java小白,java)