mybatis数组和集合的长度判断和使用:
2、判断长度
集合:<if arr.size() > 0">
数组:<if colect.length > 0">
数组:
@Insert("<script> insert into sys_dept_combine (dept_id,combine_id) " +
" <foreach collection='functionId' item='item' index='index' > \n" +
" select #{deptId},#{item}" +
" <if test='index != (functionId.length-1)'> union all </if> \n" +
" </foreach> </script>")
void insertDeptFunction(@Param("deptId") String deptId,
@Param("functionId")String[] functionId);
集合:
@Insert("<script> INSERT INTO dic_combine_item (combine_id,item_id) " +
" <foreach collection='list' item='item' index='index' > \n" +
" select #{id},#{item}" +
" <if test='index != (list.size() - 1)'> union all </if>" +
" </foreach> </script> ")
void insertCombineItem(@Param("id") String id, @Param("list")List list);