mybatis xml的无效判空

    <insert id="insert">
        <if test="xxxMappingEntityList != null and xxxMappingEntityList.size() > 0">
            INSERT IGNORE INTO
            `xxx_mapping` (
            `A_id`,
            `B_id`,
            `create_time`,
            `update_time`
            ) VALUES
            <foreach collection="xxxMappingEntityList" item="xxxMappingEntity"
                     separator="," open="" close="">
                (
                #{xxxMappingEntity.AId},
                #{xxxMappingEntity.BId},
                now(),
                now()
                )
            </foreach>
        </if>
    </insert>

 int insert(@Param("xxxMappingEntityList") List<xxxMappingEntity> xxxMappingEntityList);

这个如果插入的是null  会出错

### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Query was empty
### The error may involve defaultParameterMap
### The error occurred while setting parameters
...

"insert 出错云云..."

so, 判空<if test="xxxMappingEntityList != null and xxxMappingEntityList.size() > 0"> 这个是没意义的,

CollectionUtils.isEmpty(xxxMappingEntityList) 这个逻辑放在 xxxDao.insert的前面就好了

原文地址:https://www.cnblogs.com/balfish/p/5690713.html