使用mybatis返回int类型时
<select id="queryPerfTarget" resultType="java.lang.Integer" >
SELECT sum(perf_target) from subject
</select>
项目总是报错
org.apache.ibatis.binding.BindingException: Mapper method 'queryPerfTarget' (interface com.****.workbench.subject.dao.SubjectMapper) attempted to return null from a method with a primitive return type (int).
解决方案:(当查询出来为空时,给赋值一个默认值:MySQL使用函数ifnull())
<select id="queryPerfTarget" resultType="java.lang.Integer" >
SELECT IFNULL(sum(perf_target),0) from subject
</select>