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     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM