今天用到查询参数是一个不定元素个数的数组如int[]、String[]

在写select查询的parameterType的时候发现,如果parameterType是一个数组的话

1.配置语句中不写这个参数类型
mybatis查询当参数是数组的时候该怎么写parameterType
2.配置语句中把参数类型parameterType写成java.util.List
mybatis查询当参数是数组的时候该怎么写parameterType
3.参数数组元素是整数也可以写成
mybatis查询当参数是数组的时候该怎么写parameterType
4.mybatis查询当参数是数组的时候该怎么写parameterType
5.BUT不能写成String[]的,
这会报错 Could not resolve type alias ‘string[]’. Cannot find class: string[]


如果传入的参数整是Map<String,Object>的时候,Map里面既有数组对象元素,又有其他类型参数的时候怎么写呢?

如:参数的整体是 Map<String,Object> param=new HashMap<String,Object>

String[] str={“aaa”,“bbb”,ccc",“ddd”};

param.put(“a”,str); /把数组添加到Map参数param中以a为键/

param.put(“b”,“testb”) /把字符串添加到Map参数param中以b为键/

查询的sql应该是如下形式

SELECT * FROM test where filed_a = #{b} and filed_b in #{itema}

参数的整体类型是java.util.HashMap这个是没什么疑问的。需要注意的是foreach循环的collection直接写map中数组对象的键(测试中为a)即可

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-12-23
  • 2022-12-23
  • 2021-07-15
相关资源
相似解决方案