接口

	int addUserMap(Map<String, Object> map);

Mapper.xml

<!-- 

  Map比较灵活 传递的值为Map的key,可以为任何(野路子,不规范,但万能)
字段过多的话,Map可以只给需要的字段传参,而使用对象传参的话,需要很多的构造器
<update id="updateUser" parameterType="Map">
update mybatis.user set name = #{name} where id = #{id}
</update>
-->
<insert id="addUserMap" parameterType="Map">
insert into mybatis.user (id,name,pwd) values (#{userId},#{userName},#{userPassword})
</insert>

Test

/**
* Map的添加操作
*/
@Test
public void addUserMapTest() {
SqlSession sqlSession = MyBatisUtil.getSqlSession(); try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class); Map<String,Object> map = new HashMap<String, Object>();
map.put("userId", 6);
map.put("userName","汤姆");
map.put("userPassword", "15s66s"); int num = userMapper.addUserMap(map);
if(num > 0) {
// 提交事务
System.out.println(num);//1
sqlSession.commit();
sqlSession.close();
}
}catch(Throwable e) {
e.printStackTrace();
}finally {
sqlSession.close();
}
}

MyBatis中的Map的更多相关文章

  1. myBatis中使用Map进行遍历

    myBatis中使用Map获取key, value的方式 第一次的配置 <trim prefix=" tags =case" suffix="end"&g ...

  2. mybatis中的map.xml文件中sql语句需要分号吗?

    mybatis中的map.xml文件中sql语句需要分号吗? :你是说sql介绍的分号吗?不需要的

  3. 【mybatis】mybatis中 返回map集合

    关于mybatis返回map集合的操作: 1.mapper.xml中写一个查询返回map的sql <select id="findMap" parameterType=&qu ...

  4. Mybatis中返回Map

    在Mybatis中,我们通常会像下边这样用: 返回一个结果 User selectOne(User user); <select id="selectOne" paramet ...

  5. foreach属性-动态-mybatis中使用map类型参数,其中key为列名,value为列值

    http://zhangxiong0301.iteye.com/blog/2242723 最近有个需求,就是使用mybatis时,向mysql中插入数据,其参数为map类型,map里面的key为列名, ...

  6. Mybatis 中遍历map 参数中的 list 和 array 属性

    原文:https://blog.csdn.net/liudongdong0909/article/details/51048835 问题在项目有中遇到批量删除操作时,需要根据两个属性去删除数据,其中一 ...

  7. mybatis 中的where标签

    mybatis中的where标签可以去除 开头的 and 或者 or 但是放在后面的不行 失败的: <select id="countNotesByParam" parame ...

  8. Mybatis中SqlMapper配置的扩展与应用(3)

    隔了两周,首先回顾一下,在Mybatis中的SqlMapper配置文件中引入的几个扩展机制: 1.引入SQL配置函数,简化配置.屏蔽DB底层差异性 2.引入自定义命名空间,允许自定义语句级元素.脚本级 ...

  9. MyBatis中的resultType和resultMap

    MyBatis的查询在进行映射的时候,返回值类型可以使用resultType同时也可以使用resultMap.前者表示直接的返回值类型,一般是domain名称,当然这里可以写domain的全部路径也可 ...

随机推荐

  1. Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords (贪心)

    题意:你有\(a\)个树枝和\(b\)个钻石,\(2\)个树枝和\(1\)个钻石能造一个铁铲,\(1\)个树枝和\(2\)个钻石能造一把剑,问最多能造多少铲子和剑. 题解:如果\(a\le b\),若 ...

  2. Codeforces Round #649 (Div. 2) B. Most socially-distanced subsequence (数学,差分)

    题意:有一长度为\(n\)的数组,求一子序列,要求子序列中两两差的绝对值最大,并且子序列尽可能短. 题解:将数组看成坐标轴上的点,其实就是求每个单调区间的端点,用差分数组来判断单调性. 代码: #in ...

  3. 2019-2020 ACM-ICPC Brazil Subregional Programming Contest Problem M Maratona Brasileira de Popcorn (二分)

    题意:有\(n\)袋爆米花,某个队伍有\(c\)个队员,每个队员每秒做多可以吃\(t\)粒爆米花,但一袋爆米花只能由一个队员吃完,并且一个队员只能吃连续的一袋或几袋,不能隔着吃某一袋,求将所有爆米花吃 ...

  4. Web安全之SQL注入(原理,绕过,防御)

    首先了解下Mysql表结构 mysql内置的information_schema数据库中有三个表非常重要1 schemata:表里包含所有数据库的名字2 tables:表里包含所有数据库的所有的表,默 ...

  5. 【非原创】LightOJ - 1284 Lights inside 3D Grid【概率期望】

    学习博客: 戳这里 戳这里 戳这里 戳这里 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过后开着的灯的期望数量: 题解: ...

  6. proto3 协议指引

    一.protocal buffer 是什么? 一种序列化机制. 什么是序列化? 一种转化为可存储和传输对象的过程. 序列化的方式有很多,那么proto有什么特殊的呢? 它的英文介绍里提到了neutra ...

  7. React hox

    React hox https://github.com/umijs/hox

  8. ES2021 & Pipeline operator (|>) / 管道运算符 |>

    ES2021 & Pipeline operator (|>) / 管道运算符 |> demo "use strict"; /** * * @author xg ...

  9. git cli all in one

    git cli all in one https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud git create ...

  10. react-parent-child-lifecycle-order

    react-parent-child-lifecycle-order react parent child lifecycle order live demo https://33qrr.csb.ap ...