实现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();

 


免责声明!

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



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