【笔记】MyBatis参数处理方式
前言
MyBatis参数处理方式
多个参数的处理方式
默认方式
- 当Java向MyBatis传递了一组参数时,根据参数的传递顺序,MyBatis会自动创建一个Map集合来存储参数
- 每个参数会向Map中创建2个键值对,第一个参数的键名分别是
arg0
和param1
,值为参数值,以此类推
1 | void test(int id, String name) |
1 | <select id="test"> |
修改默认
- 可以通过
@Param()
注解修改Map中以arg
开头的键名
1 | void test(int id, String name) |
1 | <select id="test"> |
单个数据的处理方式
- 无论什么类型的数据传递到MyBatis事时,都会被MyBatis封装为Map集合
自动封装
- 如果是以下类型,默认会自动封装Map集合
- POJO类型
- Map集合
- 其他类型
Collection的封装方式
- 键为
arg0
,值为集合 - 键为
collection
,值为集合
List的封装方式
- 键为
arg0
,值为集合 - 键为
collection
,值为集合 - 键为
list
,值为集合
数组的封装方式
- 键为
arg0
,值为数组 - 键为
array
,值为数组