实现Map传参Mybatis
我这里直接使用注解方法:
DemoMapper接口:
@Select("INSERT INTO demo01(id,`name`) VALUES(#{userId},#{userName})") 通过主键获取对应值 int addDemo(Map<Integer,String> maps);
测试类:
Map<String,String> maps = new HashMap<String, String>(); maps.put("userId","15"); ---- userId是主键 maps.put("userName","冰冰"); -----userName是主键 // maps.put(13,"李四"); int i = sqlSession.insert("addDemo", maps); // int i = mapper.addDemo(demo); if(i>0){ sqlSession.commit(); System.out.println("添加成功"); }else{ System.out.println("添加失败"); } // List<Demo> list = mapper.getDemoListByLikeName("九"); // for (Demo demo:list){ // System.out.println(demo.getId()+" "+demo.getName()); // } //6、释放资源 sqlSession.close(); in.close();