mybatis 的一些错误记录

 

1、当集成做参数时,不要在 sql 里面对集成进行非空判断,如以下写法

<if test="instIdList!= null and instIdList.size() > 0">
    and inst_id_ in
    <foreach collection="instIdList" item="instanceId" index="index" open="(" close=")" separator=",">
        #{instanceId, jdbcType=VARCHAR}
    </foreach>
</if>

 

这段代码有2个问题,(1) size 后面不需要加 “()”  ;  (2)这样判断应该在外部做,不应该在sql里面做,因为如果当 list 为空时,本意应该是不查询出数据的,但实际上会查询出全部。就与本意违背了。 

posted @ 2022-06-10 10:31  aaacarrot  阅读(18)  评论(0编辑  收藏  举报