XML
<!--Map的使用-->
<insert id="addUser2" parameterType="map">
insert into user (id,name,pwd) values (#{userid},#{username},#{userpwd});
</insert>
Mapper接口
//Map的使用
int addUser2(Map<String,Object> map);
Test
//Map测试
@Test
public void addUser2() {
SqlSession sqlSession = MyBatisUtil.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
HashMap<String, Object> map = new HashMap<>();
map.put("userid",5);
map.put("username","牛七");
map.put("userpwd","12345");
int result = mapper.addUser2(map);
if (result > 0) {
System.out.println("添加成功!");
}
//增删改一定要提交事务!
sqlSession.commit();
sqlSession.close();
}
xml中parameterType="map"的map代表的是传入的整个map,只要sql语句中
取出的key在传入的map中有就可以用