MyBatis参数传递,注解开发

MyBatis接口方法中可以接受各种各样的参数,MyBatis底层对于这些参数进行不同的封装处理凡是
MyBatis提供了ParamNameResolver类来进行参数封装
MyBatis 参数封装:
1.POJO类型:直接使用,属性名,和参数占位符名称一致
2.Map集合:直接使用,键名和参数占位符名称一致
3.Collection:封装为Map集合
map.put(“arg0”,collection集合)
map.put(“collection”,collection集合)
4。List:封装为Map集合
map.put(“arg0”,list集合)
map.put(“collection”,list集合)
map.put(“list”,list集合)
5.Array:封装为map集合
map.out(“arg0”,数组)
map.out(“array”,数组)
6.其他类
*多个参数:封装为Map集合,可以使用@Param注解,替换Map集合中的默认的arg键名
map.out(“arg0”,参数值1)
map.out(“param1”,参数值1)
map.out(“arg1”,参数值2)
map.out(“param2”,参数值2)
--------------------@Param
map.out(“username”,参数值1)
## 注解开发

    @Select("select *  from tb_user where id=#{id}")
    User selectById(int id);

猜你喜欢

转载自blog.csdn.net/weixin_46362658/article/details/123970374
今日推荐