开发记错本

1.sql 查询函数可能返回null,不能用基本类型接受,如下:

<select id="findMaxSort" parameterType="java.lang.String" resultType="java.lang.Integer"  >
    select MAX(sort)
    from write_doc_material_classify where is_show=1
    <if test="classifyCode!=null and classifyCode!=''">and  classify_code !=#{classifyCode} </if>
</select>
<select id="findDistinctNum"  resultType="java.lang.Integer"  >
    select  count(distinct sort)
    from write_doc_material_classify where is_show=1

</select>
int findMaxSort(@Param("classifyCode") String classifyCode);  //错误,MAX(sort) 可能是null,int接受就会报错,应该用Integer
int findDistinctNum(); //正确,count函数可以返回0


原文地址:https://www.cnblogs.com/yuluoxingkong/p/12205614.html