mybatis使用Hashmap传递参数
mapper
1 <!--传递map的key --> 2 <insert id="addUser2" parameterType="map"> 3 insert into mybatis.user (id , name ,password ) values(#{userid},#{username},#{password}); 4 </insert>
测试
1 @Test 2 public void addUser2(){ 3 SqlSession sqlSession = MybatisUtils.getSession(); 4 //sqlSession获取mapper 5 UserMapper mapper= sqlSession.getMapper(UserMapper.class); 6 Map<String, Object> map = new HashMap<String, Object>(); 7 map.put("userid",5); 8 map.put("username","hello"); 9 map.put("password","123456"); 10 mapper.addUser2(map); 11 sqlSession.commit(); 12 sqlSession.close(); 13 }
好看请赞,养成习惯:) 本文来自博客园,作者:靠谱杨, 转载请注明原文链接:https://www.cnblogs.com/rainbow-1/p/15587475.html
欢迎来我的51CTO博客主页踩一踩 我的51CTO博客
文章中的公众号名称可能有误,请统一搜索:靠谱杨的秘密基地

浙公网安备 33010602011771号