使用ibatis将HashMap值插入到表中 [英] Inserting HashMap Values to a table using ibatis
问题描述
我在 http://old.nabble.com/insert-statement- td21157498.html
我想做同样的事情。我在我的表中有两列。我可以通过将hashmap键映射到列名称来插入哈希映射值。现在我想把键值对与表名无关。
从上面的链接粘贴。
我想编写动态插入语句,但字段和值都是动态的。
我的意思是
< insert id =someIDhereparameterClass =java.util.HashMap>
插入到table_one中(
!!! HashMap
)的值的动态列表(
! !!值
);
< / insert>
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
)值(
#col1#,#col2#,#col3#
);
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.
Pasted from the link above.
I would like to write a dynamic insert statement, but both fields and values are dynamic.
I mean
<insert id="someIDhere" parameterClass="java.util.HashMap">
insert into table_one (
!!! dynamic list of keys from the HashMap
) values (
!!! values
);
</insert>
The Hashmap could be:
HashMap<String,Integer> hm = new HashMap<String, Integer>();
hm.put("col1", 1);
hm.put("col2", 23);
hm.put("col3", 34);
then call the insert someIDhere with the hm as parameter.
insert into table_one (
COLUMN1, COLUMN2, COLUMN3
) values (
#col1#, #col2#, #col3#
);
这篇关于使用ibatis将HashMap值插入到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!