使用 ibatis 将 HashMap 值插入到表中 [英] Inserting HashMap Values to a table using ibatis

查看:21
本文介绍了使用 ibatis 将 HashMap 值插入到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 http://old.nabble.com/insert-statement- 上找到了这个td21157498.html我想做同样的事情.我的表中有两列.我可以通过将哈希映射键映射到列名来插入哈希映射值.现在我想将键值对放在表中,而不管键名如何.

I found this on http://old.nabble.com/insert-statement-td21157498.html I want to do the same thing .I have two columns in my table .I am able to insert hash map values by mapping the hashmap key to the column name.Now i want put the key values pairs in the table irrespective of key name.

从上面的链接粘贴.

我想写一个动态插入语句,但是字段和值都是动态的.

I would like to write a dynamic insert statement, but both fields and values are dynamic.

我是说

<insert id="someIDhere" parameterClass="java.util.HashMap">

    insert into table_one (

        !!! dynamic list of keys from the HashMap

    ) values (

        !!! values

    );

  </insert>

推荐答案

Hashmap 可以是:

The Hashmap could be:

    HashMap<String,Integer> hm = new HashMap<String, Integer>();
    hm.put("col1", 1);
    hm.put("col2", 23);
    hm.put("col3", 34);

然后以 hm 作为参数调用 insert someIDhere.

then call the insert someIDhere with the hm as parameter.

insert into table_one (

    COLUMN1, COLUMN2, COLUMN3

) values (

    #col1#, #col2#, #col3#

);

这篇关于使用 ibatis 将 HashMap 值插入到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆