zl程序教程

您现在的位置是:首页 >  Java

当前栏目

mybatis数组和集合的长度判断及插入

2023-02-18 16:30:17 时间

1、在使用foreach的是collection属性,该属性是必须指定的,但是在不同情况下,该属性的值是不一样的,主要有一下3种情况: 

  1. 如果传入的是单参数且参数类型是一个List的时候,collection属性值为list .
  2. 如果传入的是单参数且参数类型是一个array数组的时候,collection的属性值为array
  3. 如果dao层指定了param的name,或者dao层传的是map,collection里为param的name或map的key

2:判断长度

 集合:<if test="arr != null and arr.size() > 0">

 数组:<if test="col != null and col .length > 0">