【问题标题】:Inserting HashMap Values to a table using ibatis使用 ibatis 向表中插入 HashMap 值
【发布时间】:2012-06-21 05:08:16
【问题描述】:

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

从上面的链接粘贴。

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

我是说

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

    insert into table_one (

        !!! dynamic list of keys from the HashMap

    ) values (

        !!! values

    );

  </insert>

【问题讨论】:

  • 你能详细说明你的问题吗?您发布的链接也有解决方案。

标签: java sql hashmap ibatis


【解决方案1】:

Hashmap 可以是:

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

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

insert into table_one (

    COLUMN1, COLUMN2, COLUMN3

) values (

    #col1#, #col2#, #col3#

);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    相关资源
    最近更新 更多