如果实体类或数据库中太多参数,我们应该考虑用MAP
int addUser2(Map<String, Object> map);
Mapper.xml
<insert id="addUser2" parameterType="map" >
insert into mybatis.user(id,name,pwd) values (#{userid},#{username},#{userpassword});
</insert>
测试类
//增加用户 增删改要提交事务,用MAP
@Test
public void AddUser2(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
Map<String,Object> map = new HashMap<String, Object>();
map.put("userid",7);
map.put("username","阿飞");
map.put("userpassword","000000");
mapper.addUser2(map);
//提交事务
sqlSession.commit();
//关闭
sqlSession.close();
}
标签:lesson3,10,map,MAP,Mybatis,sqlSession,put,addUser2
From: https://www.cnblogs.com/RUI2022/p/17203419.html