转自:
Mybatis中如何传入map参数呢?
下文笔者讲述Mybatis的xml中使用map参数的方法分享,如下所示
实现思路:1.将参数类型设置为map2.在xml中直接使用map的键值获取参数即可
例:
Mybatis使用map获取键值的方法分享
xmlinsert into user (id,name,pwd) values (#{userid},#{username},#{userpwd}); Mapper接口//Map的使用int addUser(Mapmap);//测试代码 //Map测试@Testpublic void addUser2() {SqlSession sqlSession = MyBatisUtil.getSqlSession();UserMapper mapper = sqlSession.getMapper(UserMapper.class);HashMap map = new HashMap<>();map.put("userid",8888);map.put("username","java爱好者");map.put("userpwd","java265.com");int result = mapper.addUser(map);if (result > 0) {System.out.println("添加成功!");}//增删改一定要提交事务!sqlSession.commit();sqlSession.close();}